Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet add package cli support for cpm projects #4700

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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