Skip to content

Commit

Permalink
Added some more scenarios to consider, clarified problem with error m…
Browse files Browse the repository at this point in the history
…essage
  • Loading branch information
pragnya17 committed May 27, 2022
1 parent 5df6b03 commit 77e7323
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions proposed/2022/CPMDotnetCLISupport.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ Issue: [11807] (https://github.com/NuGet/Home/issues/11807)
Status: In Review

## Problem Background
The dotnet add package command allows users to add or update a package reference in a project file through the Dotnet CLI. However, when this command is used in a project that has been onboarded to Central Package Management (CPM), it poses an issue.
The dotnet add package command allows users to add or update a package reference in a project file through the Dotnet CLI. However, when this command is used in a project that has been onboarded to Central Package Management (CPM), it poses an issue as this error is thrown: `error: NU1008: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: [PackageName]`.

Projects onboarded to CPM use a `Directory.packages.props` file in the root of the repo where package versions are defined centrally. Ideally, when the `dotnet add package` command is used, the package version should only be added to the corresponding package in the `Directory.packages.props` file. However, currently the command attempts to add the package version to the <PackageReference /> in the project which conflicts with the CPM requirements that package versions must only be in the `Directory.packages.props` file.
Projects onboarded to CPM use a `Directory.packages.props` file in the root of the repo where package versions are defined centrally. Ideally, when the `dotnet add package` command is used, the package version should only be added to the corresponding package in the `Directory.packages.props` file. However, currently the command attempts to add the package version to the <PackageReference /> in the project which conflicts with the CPM requirements that package versions must only be in the `Directory.packages.props` file.

## Goals
The main goal is to add support for `dotnet add package` to be used with projects onboarded onto CPM. Regardless of whether the package has already been added to the project or not, the command should allow users to add packages or update the package version in the `Directory.packages.props` file.
Expand All @@ -16,11 +16,14 @@ The main goal is to add support for `dotnet add package` to be used with project
Users wanting to use CPM onboarded projects and dotnet CLI commands.

## Solutions
When `dotnet add package` is executed in a project onboarded to CPM any one of the following things should happen:
When `dotnet add package` is executed in a project onboarded to CPM any one of the following things must happen:
- If the package does not already exist, it should be added along with the appropriate package version to `Directory.packages.props`. Only the package name (not the version) should be added to `<PackageReference>` in the project file.
- If the package already exists in `Directory.packages.props` the version should be updated in `Directory.packages.props`. The `<PackageReference>` in the project file should not change.

In all of the cases above, if no version is specified in the CLI command the latest version should be added to `Directory.packages.props`.

While the above cases must be considered to solve the issue, there are a few other cases that can be considered to make the product more usable:
- If the project is onboarded to CPM by setting the <ManagePackageVersionsCentrally> to true, but the `Directory.packages.props` file has not been created yet the file should be created. At this point, package references can be updated according to the cases discussed above.
- If the `Directory.packages.props` file has been created but the <ManagePackageVersionsCentrally> property has not been set to true, it should be set to true.


0 comments on commit 77e7323

Please sign in to comment.