Skip to content

Commit

Permalink
dotnet add package cli support for cpm projects (#4700)
Browse files Browse the repository at this point in the history
  • Loading branch information
pragnya17 authored Jul 12, 2022
1 parent 0707bff commit 93da94e
Show file tree
Hide file tree
Showing 7 changed files with 941 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public async Task<int> ExecuteCommand(PackageReferenceArgs packageReferenceArgs,
typeConstraint: LibraryDependencyTarget.Package)
};

msBuild.AddPackageReference(packageReferenceArgs.ProjectPath, libraryDependency);
msBuild.AddPackageReference(packageReferenceArgs.ProjectPath, libraryDependency, packageReferenceArgs.NoVersion);
return 0;
}

Expand Down Expand Up @@ -219,7 +219,7 @@ public async Task<int> ExecuteCommand(PackageReferenceArgs packageReferenceArgs,
// generate a library dependency with all the metadata like Include, Exlude and SuppressParent
var libraryDependency = GenerateLibraryDependency(updatedPackageSpec, packageReferenceArgs, restorePreviewResult, userSpecifiedFrameworks, packageDependency);

msBuild.AddPackageReference(packageReferenceArgs.ProjectPath, libraryDependency);
msBuild.AddPackageReference(packageReferenceArgs.ProjectPath, libraryDependency, packageReferenceArgs.NoVersion);
}
else
{
Expand All @@ -239,7 +239,8 @@ public async Task<int> ExecuteCommand(PackageReferenceArgs packageReferenceArgs,

msBuild.AddPackageReferencePerTFM(packageReferenceArgs.ProjectPath,
libraryDependency,
compatibleOriginalFrameworks);
compatibleOriginalFrameworks,
packageReferenceArgs.NoVersion);
}

// 6. Commit restore result
Expand Down Expand Up @@ -276,6 +277,9 @@ private static LibraryDependency GenerateLibraryDependency(
// update default packages path if user specified custom package directory
var packagesPath = project.RestoreMetadata.PackagesPath;

// get if the project is onboarded to CPM
var isCentralPackageManagementEnabled = project.RestoreMetadata.CentralPackageVersionsEnabled;

if (!string.IsNullOrEmpty(packageReferenceArgs.PackageDirectory))
{
packagesPath = packageReferenceArgs.PackageDirectory;
Expand Down Expand Up @@ -314,6 +318,7 @@ private static LibraryDependency GenerateLibraryDependency(
if (dependency != null)
{
dependency.LibraryRange.VersionRange = version;
dependency.VersionCentrallyManaged = isCentralPackageManagementEnabled;
return dependency;
}
}
Expand All @@ -324,7 +329,8 @@ private static LibraryDependency GenerateLibraryDependency(
LibraryRange = new LibraryRange(
name: packageReferenceArgs.PackageId,
versionRange: version,
typeConstraint: LibraryDependencyTarget.Package)
typeConstraint: LibraryDependencyTarget.Package),
VersionCentrallyManaged = isCentralPackageManagementEnabled
};
}

Expand Down
9 changes: 9 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -753,4 +753,8 @@ The search is a case-insensitive string comparison using the supplied value, whi
Non-HTTPS access will be removed in a future version. Consider migrating to 'HTTPS' sources.</value>
<comment>0 - The command name. Ex. Push/Delete. 1 - list of server uris</comment>
</data>
<data name="Info_AddPkgCPM" xml:space="preserve">
<value>PackageReference for package '{0}' added to '{1}' and PackageVersion added to central package management file '{2}'.</value>
<comment>0 - The package ID. 1 - Directory.Packages.props file path. 2 - Project file path.</comment>
</data>
</root>
Loading

0 comments on commit 93da94e

Please sign in to comment.