Jenkins - Run a NuGet package restore to generate this file

I had the same problem, getting the same error:

error : Package <package> was not found. 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. [<path>]

I was able to solve it using MSBuild /t:restore instead of dotnet restore.

See: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target


UPDATE: It's worth mentioning that problems in Jenkins are discussed in depth in this other answer.

The hint by @Mat didn't work for me: the /t:restore is currently not able to restore nuget packages for projects using package.config, as I mention here. What worked for me is the following:

call "%PROGRAMFILES(X86)%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
nuget restore CodeBinder.sln
MSBuild Solution.sln /p:Configuration=Release /p:Platform="Any CPU" /t:build /restore
pause

It basically requires to download the nuget CLI from official site[1], Windows x86 Commandline section. The switch /restore , as pointed here, fixed the partially completed Nuget restore error, similarly to MSBuild /t:restore, but it can be done in conjunction with /t:build.

[1] https://www.nuget.org/downloads