Dotnet tool restore fails randomly

Recently I’ve started seeing in several workflows, for no apparent reason, no recognizable pattern, to see this error, when running a simple “dotnet tool restore”:

error NU1101: Unable to find package benchmarkdotnet.tool. No packages exist with this id in source(s): C:\Program Files\dotnet\sdk\NuGetFallbackFolder, Microsoft Visual Studio Offline Packages

Package "benchmarkdotnet.tool" failed to restore, due to Microsoft.DotNet.ToolPackage.ToolPackageException: The tool package could not be restored.
   at Microsoft.DotNet.Tools.Tool.Install.ProjectRestorer.Restore(FilePath project, PackageLocation packageLocation, String verbosity)

No matter what the content of the workflow, no matter the place the action is in the flow, one time it would fail, another time it would succeed, seemingly completely randomly.

Any ideas why ?

Turns out this is not an isolated problem and many people have experienced it.

If you are one of us, I found a solution mentioned in this thread - https://github.com/actions/setup-dotnet/issues/155

The solution is this step:

- name: Clean
  run: dotnet clean path/to/project.sln --configuration Release && dotnet nuget locals all --clear

If you are using Powershell explicitly, use this instead:

- name: Clean
  run: |
    dotnet clean path/to/project.sln --configuration Release 
    dotnet nuget locals all --clear

There seems to be a problem (unknown as of the writing of this comment) that is fixed by this deep cleaning and only then restoring .NET tools.

1 Like