Repository navigation
Description
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
esbenbach commentedon Jun 21, 2022
Minimal repro (rename Directory.Packages.props before restoring to see the difference)
CPMRepro.zip
jeffkl commentedon Jun 21, 2022
At this time, you must use a file named
Directory.Packages.propsor 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
nkolev92 commentedon Jun 23, 2022
Team Triage: Closing per @jeffkl's comment.