NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

[Bug]: NuGet Package Manager does not update Directory.Packages.props #11826

Open sbenzenko opened 2 years ago

sbenzenko commented 2 years ago

NuGet Product Used

Visual Studio Package Management UI Visual Studio Package Manager Console

Product Version

dotnet 6.0.300, Visual Studio 17.2.1

Worked before?

No response

Impact

It's more difficult to complete my work

Repro Steps & Context

When using Central Package Management with Directory.Packages.props file on solution level, trying to update package from Visual Studio Package Management UI or via Package Management Console results in package version being updated in project's .csproj file rather than in Directory.Packages.props file. It adds Version="..." attribute to <PackageReference /> in .csproj. That in turn causes the following compilation error: NU1008 Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items

Had to manually remove Version="..." from .csproj and update it in Directory.Packages.props to make it work. image

Verbose Logs

No response

jeffkl commented 2 years ago

@sbenzenko Thank you for your report, we are actively working on Visual Studio support as well as dotnet CLI support for CPM.

At a top level, the Visual Studio work is tracked here: https://github.com/NuGet/Home/issues/9015

reduckted commented 2 years ago

@jeffkl Does that mean we can't use Central Package Management and install new packages in Visual Studio?

I've switched to CPM and Visual Studio can restore the packages just fine, but when I try to install a package, I get the error mentioned in this issue and the package installation is rolled back, so I can't install any packages at all.

NU1008: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: MyPackage.
Package restore failed. Rolling back package changes for 'MyProject'.

That seems to go against what the documentation says about this feature:

The feature is available across all NuGet integrated tooling.

jeffkl commented 2 years ago

@jeffkl Does that mean we can't use Central Package Management and install new packages in Visual Studio?

@reduckted That's correct. We are working on the tooling side of things like Visual Studio and dotnet so that they work with CPM. Some of the work is already done and will be available in upcoming releases. We're tracking the work here: https://github.com/NuGet/Home/issues/11752

Sorry that wasn't clear from the documentation.

awattar commented 1 year ago

@jeffkl any ETA for this basic functionality?

yorschor commented 2 months ago

This is also a Problem when using .Net Framework projects with the legacy project format and Visual Studio. From reading the CPM docu this should work.

"Central package management applies to all -based MSBuild projects (including legacy CSPROJ) as long as compatible tooling is used."

Restoring works. Upgrading via the Rider NugGet manager works. Upgrading with the Visual Studio tools does not :( image


Visual Studio 17.10.5 .NET Framework 4.6.2 & 4.7.2