You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[CPM] Don't add Package versions when creating a new project if CPM is enabled #12967
When you create a new project with certain templates, PackageReferences are added by default. Even if CPM is enabled, the Package version is specified in the PackageReference which leads to a compile error.
Desired Behavior
If CPM is enabled, the package version should not be specified by default.
Additional Context
This allows a developer to create a new project and compile it without any initial errors.
Reacted by cremor, Sean Leonard, Erik O'Leary and Johan Bennink
However, my understanding is that new project template implementations are maintained by our partner teams. They leverage the NuGet SDK to add a package reference. @jeffkl, should this request be routed to the project system team? Does the NuGet SDK have any API to identify if the solution has been onboarded onto CPM? If yes, I believe partner teams can leverage the SDK to add the package version to the Directory.Packages.Props file if the solution is already onboarded onto CPM. May be the presence of Directory.Packages.Props is sufficient to ensure that project has been onboarded onto CPM.
I think similar feature requests may arise in the future for dotnet new CLI commands.
I think this is more templating work than NuGet, since we don't really control all the templates. The templates themselves add a PackageReference item directly in the project, and that's simply hard to control.
@nkolev92 I did have the same issue as mentioned here and in linked issue and maybe I have some usefull information for you to hopefully get some kind of fix.
Solution used
Powershell commandline at our solution root folderC:\Users\Me\source\MyApp\
(ommitting known dotnet add package output for brevity)
Suggestion
So my assumtion of this is, it does work also in CPM, but it fails if we are not providing the ProjectName because in the shown solution structure, thats completly correct message: We do have a .sln and maybe .slnf files in the root dir, but no particular .csproj file.
But as I filed: just as I provided the Name of the FOLDER where the project file I want this to be added in the end, it did just fine.
Maybe there should be added an option for solution or if not provided any project and found the CPM tag set to true, it should default to just add the PackageVersion into this, because then it would not fail.
Activity
kartheekp-ms commentedon Oct 26, 2023
I am able to reproduce the issue, and it makes sense to me. The repro steps are simple.
However, my understanding is that new project template implementations are maintained by our partner teams. They leverage the NuGet SDK to add a package reference. @jeffkl, should this request be routed to the project system team? Does the NuGet SDK have any API to identify if the solution has been onboarded onto CPM? If yes, I believe partner teams can leverage the SDK to add the package version to the Directory.Packages.Props file if the solution is already onboarded onto CPM. May be the presence of
Directory.Packages.Propsis sufficient to ensure that project has been onboarded onto CPM.I think similar feature requests may arise in the future for
dotnet newCLI commands.nkolev92 commentedon Oct 27, 2023
There's a duplicating in templating: dotnet/aspnetcore#48569
They have a feature ask for us, but there's some other ways of doing it that are not complete blocked on
#12629
dotnet/templating#6187 (comment)
nkolev92 commentedon Oct 27, 2023
I think this is more templating work than NuGet, since we don't really control all the templates. The templates themselves add a PackageReference item directly in the project, and that's simply hard to control.
nkolev92 commentedon Oct 30, 2023
Team Triage: Assigning to @jeffkl to help us better understand the pieces and the ownership of the bugs.
DevTKSS commentedon Jul 3, 2025
@nkolev92 I did have the same issue as mentioned here and in linked issue and maybe I have some usefull information for you to hopefully get some kind of fix.
Solution used
Powershell commandline at our solution root folder
C:\Users\Me\source\MyApp\Structure:
My CPM tag is added in
Directory.Build.propsThis is not working:
produces this Error
This is Working WITH CPM:
dotnet add package Some.Package.Name --project MyApp.Server(ommitting known dotnet add package output for brevity)
Suggestion
So my assumtion of this is, it does work also in CPM, but it fails if we are not providing the ProjectName because in the shown solution structure, thats completly correct message: We do have a
.slnand maybe.slnffiles in the root dir, but no particular.csprojfile.But as I filed: just as I provided the Name of the FOLDER where the project file I want this to be added in the end, it did just fine.
Maybe there should be added an option for solution or if not provided any project and found the CPM tag set to true, it should default to just add the PackageVersion into this, because then it would not fail.