Jenkins - 运行 NuGet 包还原以生成此文件

Jenkins - Run a NuGet package restore to generate this file

当我在 Jenkins 构建服务器上构建 .NET Standard 2.0 库时

C:\Program Files\dotnet\sdk.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 restore <Solution Name>

当我在构建开始前清理我的工作区时,该解决方案没有帮助我。

因此,我在 MSBuild 之前插入了命令,但失败了

C:\Program Files\dotnet\sdk.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...

我有同样的问题,得到同样的错误:

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

UPDATE:值得一提的是,Jenkins 中的问题在另一个 .

中进行了深入讨论

@Mat 的提示对我不起作用:/t:restore 目前无法为使用 package.config 的项目恢复 nuget 包,正如我提到的 。对我有用的是:

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

基本上需要从官方站点[1]、Windows x86 命令行部分下载 nuget CLI。开关 /restore ,正如 指出的那样,修复了部分完成的 Nuget 恢复错误,类似于 MSBuild /t:restore,但它可以与 /t:build.[=20= 一起完成]

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