Skip to content

[CPM] Don't add Package versions when creating a new project if CPM is enabled #12967

Open

Description

@adcloeshelle

NuGet Product(s) Affected

Visual Studio, dotnet.exe

Current Behavior

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.

Activity

  1. kartheekp-ms commented on Oct 26, 2023

    @kartheekp-ms
    Contributor

    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.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.

  2. added
    Functionality:VisualStudioUI
    Area:RestoreCPM
    and removed on Oct 26, 2023
  3. nkolev92 commented on Oct 27, 2023

    @nkolev92
    Member

    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)

  4. nkolev92 commented on Oct 27, 2023

    @nkolev92
    Member

    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.

  5. nkolev92 commented on Oct 30, 2023

    @nkolev92
    Member

    Team Triage: Assigning to @jeffkl to help us better understand the pieces and the ownership of the bugs.

  6. added
    Priority:2
    and removed
    Functionality:VisualStudioUI
    on Oct 30, 2023
  7. DevTKSS commented on Jul 3, 2025

    @DevTKSS

    @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:

    MyApp.sln
    - MyApp.Client/MyApp.Client.csproj
    - MyApp.DataContracts/MyApp.DataContracts.csproj
    - MyApp.Server/MyApp.Server.csproj
    
    • Place Project in same directory as Solution

    My CPM tag is added in Directory.Build.props

    <Project>
      <PropertyGroup>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
      </PropertyGroup>
    </Project>

    This is not working:

    dotnet add package Some.Package.Name

    produces this Error

    Could not find any project in `C:\Users\Me\source\MyApp\`.
    

    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 .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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area:RestoreCPMFunctionality:RestorePriority:2Product:VS.ClientProduct:dotnet.exeTriage:InvestigateType:DCR

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions