The Curious Case of the NU1008 Error: A .NET Build Story

Recently, I ran into a puzzling build issue while working on our large ERP solution. What started as a routine build turned into a classic developer mystery—one that took a bit of head-scratching, a lot of searching, and, ultimately, a helping hand from GitHub Copilot.
The Problem Appears
It all began when I tried to build the solution in Visual Studio. To my surprise, the build failed with a cryptic error. Not one to give up easily, I switched to the command line and ran:
dotnet build ERP.sln
To my relief, this command succeeded! But the story didn’t end there.
Enter MSBuild
Since some of our CI/CD processes use MSBuild directly, I decided to try:
msbuild ERP.sln
This time, the build failed again, but with a more specific error:
NU1008: When using Central Package Version Management, do not specify the version in the PackageReference elements. The version is defined in the central package version management file.
The Investigation
The error message pointed to Central Package Version Management (CPVM) and hinted that somewhere, a <PackageReference>
was specifying a Version
attribute, which isn’t allowed when using a Directory.Packages.props file.
I methodically searched through all the .csproj
files in the solution for any <PackageReference ... Version="...">
entries. I ran:
Select-String -Path *.csproj -Pattern 'Version="'
But found nothing. Every project was clean—no package versions specified in the project files.
The Frustration
At this point, I was stumped. Visual Studio build failed, dotnet build
worked, and msbuild
failed with NU1008. I double-checked the Directory.Packages.props file and all project files. Everything looked correct.
I even tried cleaning the solution:
dotnet clean ERP.sln
Remove-Item -Recurse -Force .\bin, .\obj
dotnet restore ERP.sln
But the error persisted with msbuild
.
Copilot to the Rescue
After spending more time than I’d like to admit, I turned to GitHub Copilot for advice. Copilot suggested that sometimes, stale build artifacts or cached package information can cause this error to persist, even if the source files are correct.
Following Copilot’s advice, I:
Deleted all bin and
obj
folders in every project.Ran a full
dotnet restore
.Rebuilt the solution.
And just like that, the error disappeared! Both dotnet build
and msbuild
succeeded.
The Lesson
This experience was a reminder that sometimes, build errors can be caused by leftover artifacts or caches, not just by the code or configuration itself. When using CPVM, always ensure:
No
<PackageReference>
in your.csproj
files specifies aVersion
attribute. Obviously, that wasn’t the problem here.The Directory.Packages.props file is the single source of truth for package versions.
If you hit persistent errors, try cleaning all build outputs and restoring packages from scratch. Although, I with Microsoft would have address this issue.
And if you’re stuck, don’t hesitate to ask Copilot for help—it might just save you a few hours of frustration!
Error Message:
NU1008: When using Central Package Version Management, do not specify the version in the PackageReference elements. The version is defined in the central package version management file.
Key Commands Used:
dotnet build ERP.sln
msbuild ERP.sln
Select-String -Path *.csproj -Pattern 'Version="'
dotnet clean ERP.sln
Remove-Item -Recurse -Force .\bin, .\obj
dotnet restore ERP.sln
Thanks, Copilot!
Subscribe to my newsletter
Read articles from Andy Li directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
