Skip to content

[Bug]: CPM cli tooling required Directory.Packages.props visual studio does not #11903

Closed

Description

@esbenbach

NuGet Product Used

dotnet.exe, MSBuild.exe, NuGet.exe

Product Version

dotnet 6.0.6 SDK 6.0.301

Worked before?

No response

Impact

It bothers me. A fix would be nice

Repro Steps & Context

Given a .csproj file where central package management is enabled by importing some msbuild file (props, targets or whatever). Visual Studio (and i am guessing msbuild) determines that CPM is toggled on and restores packages correcly.

using dotnet restore on the same project fails to toggle CPM and thus restores without a lower bound version.

Adding an EMPTY Directory.Packages.props file to the root, somehow triggers dotnet restore to look at the properties imported by the .csproj file, and CPM now works as intended.

The docs describe the use of CPM via Directory.Packages.props but it seems like a weird requirement now that just the bare existence of such a file toggles CPM "capabilities" and that Visual Studio/MSBuild works just fine without it.

I should note: An EMPTY Directory.Packages.props file causes visual studio to fail, but adding an empty <Project /> element satisfies both dotnet and Visual Studio.

Verbose Logs

Without Directory.Packages.props:


dotnet restore .\CPMRepro.sln --no-cache
  Determining projects to restore...
C:\Code\Experiments\CPMRepro\CPMRepro\CPMRepro.csproj : warning NU1604: Project dependency Newtonsoft.Json does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results. [C:\Code\Experiments\CPMRepro\CPMRepro.sln]
C:\Code\Experiments\CPMRepro\CPMRepro\CPMRepro.csproj : warning NU1701: Package 'Newtonsoft.Json 3.5.8' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework
,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project. [C:\Code\Experiments\CPMRepro\CPMRepro.sln]
  Restored C:\Code\Experiments\CPMRepro\CPMRepro\CPMRepro.csproj (in 374 ms).

With an EMPTY Directory.Packages.props:

 dotnet restore .\CPMRepro.sln --no-cache
  Determining projects to restore...
  The project C:\Code\Experiments\CPMRepro\CPMRepro\CPMRepro.csproj is using CentralPackageVersionManagement, a NuGet preview feature.
  Restored C:\Code\Experiments\CPMRepro\CPMRepro\CPMRepro.csproj (in 104 ms).

Activity

  1. esbenbach commented on Jun 21, 2022

    @esbenbach
    Author

    Minimal repro (rename Directory.Packages.props before restoring to see the difference)
    CPMRepro.zip

  2. added
    Resolution:ByDesign
    and removed on Jun 21, 2022
  3. jeffkl commented on Jun 21, 2022

    @jeffkl
    Contributor

    At this time, you must use a file named Directory.Packages.props or you must set an MSBuild property to indicate what file you want to use. Using your own file and importing it manually is not a supported scenario.

    https://docs.microsoft.com/en-us/nuget/consume-packages/central-package-management#enabling-central-package-management

  4. nkolev92 commented on Jun 23, 2022

    @nkolev92
    Member

    Team Triage: Closing per @jeffkl's comment.

  5. added
    Area:RestoreCPM
    on Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area:RestoreCPMResolution:ByDesignType:Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions