Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins - Run a NuGet package restore to generate this file

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...

like image 792
ibocon Avatar asked Jul 23 '18 18:07

ibocon


People also ask

Was not found it might have been deleted since NuGet restore otherwise NuGet restore might have only partially completed?

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.

Does MSBuild restore NuGet packages?

msbuild -t:Restore will restore nuget packages for projects with PackageReference nuget management format.


2 Answers

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

like image 63
Mat Avatar answered Oct 27 '22 16:10

Mat


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

like image 31
ceztko Avatar answered Oct 27 '22 18:10

ceztko