【问题标题】:Cannot run dotnet build in a CI Server. Unable to resolve nuget packages无法在 CI 服务器中运行 dotnet build。无法解析 nuget 包
【发布时间】:2019-08-16 21:03:17
【问题描述】:

当我们的 CI 服务器(CruiseControl.NET 以管理员身份运行)运行时

dotnet build foo.sln

它失败并显示以下消息,例如

错误 NU1100:无法解析“Serilog (>= 2.7.1)” '.NETCoreApp,版本 = v2.2'。 [C:\path\to\foo.sln]

Serilog 只是一个例子。实际上每个 nuget 包都会导致相同的错误。

为什么?

cmd.exe 运行相同的命令成功。

这个问题似乎与一些已经提出的问题重复,但我不这么认为(其他问题不同)。

【问题讨论】:

    标签: .net-core continuous-integration nuget


    【解决方案1】:

    由于 nuget 源添加有效,我不确定您为什么需要另一种方式。这是在构建机器上编辑全局 nuget.config 的最直接方法。

    但要回答您的问题,您可以临时添加 nuget 源:

    dotnet restore -s https://artifactory.example.com/api/nuget/nuget.org
    

    来自How do I register a new NuGet package source

    或者您可以在放置良好的 nuget.config 中指定 nuget 源(包括 nuget.org)。 “好放置”通常与 sln 位于同一文件夹中,因此可以将其提交到构建机器。

    【讨论】:

    • 我将上述命令作为构建服务器脚本运行(一次)以添加 nuget 源。换句话说,我必须在正确的上下文中运行它(作为构建服务器运行脚本的同一用户)。
    • 我可以在运行该脚本后删除它。
    【解决方案2】:

    看来我必须在 CI 服务器中运行它

    nuget sources add nuget.org
    

    我只需要这样做一次。

    也许有一种方法可以使用dotnet 命令而不是使用nuget.exe 添加该nuget 源。

    【讨论】:

      猜你喜欢
      • 2015-07-08
      • 2023-03-28
      • 1970-01-01
      • 2018-07-21
      • 1970-01-01
      • 2022-10-19
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多