All of a sudden my solution which is 3 or 4 years old...is throwing errors. I was never using this feature. My solution has 10 projects in it, and I had made no code changes, visual studio updates, no sdk changes. ChatGPT has been no help. All i want is for my application compile again so i can make some changes...the error code is NU1008
here are some of the errors:
"Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: MudBlazor;Microsoft.AspNetCore.Components.Web."
"Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: Microsoft.Extensions.Configuration.UserSecrets;Microsoft.Azure.Functions.Worker.Extensions.Timer;Microsoft.Azure.Functions.Worker;Azure.Extensions.AspNetCore.Configuration.Secrets;Microsoft.Graph;Newtonsoft.Json;Microsoft.ApplicationInsights.AspNetCore;Microsoft.Azure.Functions.Worker.Extensions.Http;Microsoft.Azure.Functions.Worker.Sdk."
The build system thinks that your solution has Central Package Management (CPM) enabled while your package references are not configured to support said setup.
If you did not change anything in your setup, something must be setting ManagePackageVersionsCentrally configuration property to True for you outside of your project files. The most probable culprit is a file named Directory.Packages.props but it could be other files like Directory.Build.props or Directory.Build.targets.
These files apply properties for all projects in the directory where they are located and all of its sub-directories. They don't need to be included in the relevant .csproj or .sln file to take effect.
Technically, these files are searched recursively in parent directories from the project that is being built so they may be located in any directory up to the drive root, possibly completely outside of your project. Once a relevant file is found, the search ends unless the file explicitly causes additional search. To quickly rule out this issue, you can create such file in your project. See also the relevant documentation.
The CPM configuration property might even be set as an environment variable on your system.
It's also possible that some package pulls such configuration, albeit that should not be the case if you did not change anything in the projects/references.
Note also that the tooling that supports CPM was released in May 2022 so it's quite probable that some of the tooling you use got updated as this feature did not exist 3 years ago. You wouldn't be getting this error from pre-CPM tooling. dotnet gets updated as part of Windows Update automatically - I'm quite confident that if you used dotnet --version, you'd see a newer version than that of ~3 years ago.
That being said, these are only pointers where to look, any exact solution would be specific to your case and not a general answer. If neither of these pointers help, you'll probably have to check the diagnostic logs of dotnet restore or whatever command triggers the error for you.
You might want to start with printing out the value of ManagePackageVersionsCentrally variable during build to ensure this answer is not totally off, though. See How to output a variable value to the log from MSBuild.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With