I'm having an issue with VS2019 profesional 16.5.5 and 16.5.4 with my C# multi-project solution. It compiles, tests and executes correcly, but in the background I have the constant restore of nuget packages, completing once every few seconds. The CPU is close to 100%.
I have tried Update-Package -reinstall
, nuget locals all --clear
(from: How do I fix this NuGet Restart loop in Visual Studio 2017?), updating VS, removing my .vs
folder, cleaning the solution, checking out the project again from git and even restarting. Nothing seems to help.
The project has a few main projects: two console, one AspNetCore, one WPF. They use common libs in Standard 2.0 or shared C# projects.
The Package Manager log in Output window has hundereds of entries like:
Time Elapsed: 00:00:00.7441577
========== Finished ==========
Time Elapsed: 00:00:00.8448774
========== Finished ==========
Time Elapsed: 00:00:00.8410551
========== Finished ==========
Time Elapsed: 00:00:00.7351174
========== Finished ==========
Time Elapsed: 00:00:00.7997720
========== Finished ==========
Time Elapsed: 00:00:00.9367757
========== Finished ==========
Unloading some projects helps a bit, but only temporarily - until I load them again.
How can I fix the constant Nuget package restore issue?
Restore packages manually using Visual StudioEnable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.
In Visual Studio, the Package Manager Console provides many flexible options for updating and reinstalling packages. On the Installed tab, select a package, record its name, then select Uninstall. Switch to the Browse tab, search for the package name, select it, then select Install).
It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. Here are some actions you can take to resolve this error: Add the /restore option to your MSBuild.exe command.
I found what causes the issue. Some time ago I tried adding auto versioning to the console projects (with help of Auto Versioning in Visual Studio 2017 (.NET Core)). To be exact, I added to my .csproj
file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- ... -->
<VersionPrefix>1.1</VersionPrefix>
<VersionSuffix>$([System.DateTime]::UtcNow.ToString(yyyyMMddTHHmmss))</VersionSuffix>
</PropertyGroup>
<!-- ... -->
</Project>
This was the direct cause of the issue. When commenting out the dynamic expression in VersionSuffix
, the issue disappeared. What is more interesting, changing to yyyyMMddTHHmm
(removed ss
) also fixed this. And no, it did not change the frequency of Nuget restore to minutely - it stopped completely.
Even more, I have found a post on Microsoft Developer forums that details the same issue. The post has been since removed, but I managed to archive it for purposes of this answer. The post has just been moved: Using current datetime as VersionSuffix in csproj causes restoring of packages forever
.
I know you found where the issue was coming from, but here is the fix, for those who want to keep the seconds in their version number.
Add the following to your .csproj:
<PropertyGroup>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix Condition="'$(DesignTimeBuild)' != 'true' OR '$(BuildingProject)' == 'true'">beta-$([System.DateTime]::UtcNow.ToString(yyyyMMdd-HHmmss))</VersionSuffix>
</PropertyGroup>
It nicely updates all various places with the right versioning string, including your .dll and NuGet, only when building the project (and not at design time).
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