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 and martinrrm committed Oct 5, 2022
1 parent a5baa60 commit 7eda4b2
Show file tree
Hide file tree
Showing 7 changed files with 939 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.

3 changes: 3 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -760,5 +760,8 @@ Non-HTTPS access will be removed in a future version. Consider migrating to 'HTT
<data name="Error_InvalidCultureInfo" xml:space="preserve">
<value>Invalid culture identifier in {0} environment variable. Value read is '{1}'</value>
<comment>0 - Environment variable name, 1 - value set in environment variable</comment>
<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 7eda4b2

Please sign in to comment.