代码之家  ›  专栏  ›  技术社区  ›  ibocon

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

  •  6
  • ibocon  · 技术社区  · 6 年前

    当我在Jenkins Build Server上构建.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包安装程序 可以帮我。但我不知道如何升级 Nuget包安装程序 通过命令行…

    2 回复  |  直到 6 年前
        1
  •  4
  •   Mat    6 年前

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

    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

        2
  •  1
  •   ceztko Jeff Davis    6 年前

    更新 :值得一提的是,詹金斯的问题在另一个问题中得到了深入的讨论。 answer .

    @mat的提示对我不起作用: /t:restore 当前无法为使用的项目还原nuget包 package.config 如我所说 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
    

    它基本上需要从官方网站[1]的Windows x86命令行部分下载nuget cli。开关 /restore ,如图所示 here ,修复了部分完成的nuget还原错误,类似于 MSBuild /t:restore 但可以与 /t:build .

    〔1〕 https://www.nuget.org/downloads