Jenkins - Run a NuGet package restore to generate this file

ibocon picture ibocon · Jul 23, 2018 · Viewed 21k times · Source

When I build .NET Standard 2.0 Library on Jenkins build server

C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error : Assets file 'C:\Jenkins\workspace\<Project>\Sources\Library\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\Jenkins\workspace\<Project>\Sources\Library\Library.csproj]

I got an error above in build log.

I searched about error and I found solution

However, when running:

dotnet restore <Solution Name>

the solution does not help me out when I clean my workspace before build starts.

Therefore, I insert command before MSBuild but I failed with

C:\Program Files\dotnet\sdk\2.1.302\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error : Package Microsoft.CodeAnalysis.CSharp.Workspaces, version 2.8.0 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. [C:\Jenkins\workspace\<Project>\Sources\Web\Web.csproj]

According to Solution reference, maybe upgrade Nuget Package Installer could help me out. But I do not know how can I upgrade Nuget Package Installer by command line...

Answer

Mat picture Mat · Aug 24, 2018

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