当我在Jenkins构建服务器上构建.NET Standard 2.0库时
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]
上面的构建日志中出现错误。
我搜索了错误,然后发现了solution
但是
dotnet resotre <Solution Name>
在开始构建之前清理工作区时,该解决方案无法解决问题。
因此,我在MSBuild之前插入了命令,但失败了
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]
根据Solution reference,也许升级 Nuget Package Installer 可以帮助我。但是我不知道如何通过命令行升级 Nuget Package Installer ...
答案 0 :(得分:4)
我遇到了同样的问题,得到了同样的错误:
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>]
我能够使用MSBuild /t:restore
而不是dotnet restore
来解决它。
请参阅:https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#restore-target
答案 1 :(得分:1)
更新:值得一提的是,其他answer中对詹金斯中的问题进行了深入讨论。
@Mat的提示对我不起作用:/t:restore
当前无法使用package.config
为项目恢复nuget包,正如我提到的here。对我有用的是:
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
基本上,它需要从Windows x86命令行部分的官方网站[1]下载nuget CLI。指向here的开关/restore
修复了部分完成的Nuget恢复错误,类似于MSBuild /t:restore
,但可以与/t:build
一起完成。