如何在 Ubuntu 14.04 上使用 dotnet CLI 注册新的 NuGet 包源



我在 Ubuntu 14.04 上运行 .NET Core 1.1.0,目标是在 Ubuntu 上的 Docker 中托管我的 Web API。 我想在 Ubuntu 上构建我的包,但一些 NuGet 引用托管在内部 NuGet 存储库 (Artifactory( 上。 添加包源后,这在 Windows 上的 VS2015 中工作正常,但是当我运行时:

dotnet restore

在 Ubuntu 上,托管在公共 NuGet 存储库上的包下载正常,但 Artifactory 上的包失败:

error: Unable to resolve 'Mercury.BaseModel (>= 1.1.0)' for '.NETCoreApp,Version=v1.1'.

我在 home<user>.nugetNuGetNuGet.Config 处找到了一个 NuGet 配置文件,并添加了 Artifactory 存储库,如下所示:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Artifactory-DEV" value="https://theluggage-agct.gray.net/artifactory/api/nuget/nuget-institutional-development-local" protocolVersion="3"/>
  </packageSources>
</configuration>

但我仍然遇到同样的错误。

安装 .NET Core SDK 后,NuGet 本身不起作用,我正在使用上述dotnet restore - 是否有类似的配置,我必须为 dotnet CLI 编辑(必须使用 NuGet?(还是我需要做其他事情?

谢谢!

Dotnet CLI 还原可以将 -s 作为源源 URL,因此如果您有具有远程存储库的 Artifactory nuget.org。

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

参考:

  • https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore?tabs=netcore2x

  • https://www.jfrog.com/confluence/display/RTF/NuGet+Repositories

毕竟,我很快发现了我错过的 2 个问题:

  1. 我使用 sudo -i 以 root 身份运行,试图解决问题,因此没有拾取我在 \home 文件夹中设置的 NuGet 配置。
  2. 回到我自己的登录,然后我得到一个错误:

    error: Unable to load the service index for source https://theluggage-agct.gray.net/artifactory/api/nuget/nuget-institutional-development-local.
    error:   The content at 'https://theluggage-agct.gray.net/artifactory/api/nuget/nuget-institutional-development-local' is not a valid JSON object.
    error:   Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
    

事实证明,我们的Artifactory NuGet存储库返回与NuGet v2兼容的XML。 我更改了配置文件以将存储库设置为 v2,它现在可以工作了。 因此,从上面,在

home<user>.nugetNuGetNuGet.Config

添加新的存储库 URL,并正确获取版本设置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Artifactory-DEV" value="https://theluggage-agct.gray.net/artifactory/api/nuget/nuget-institutional-development-local" protocolVersion="2"/>
  </packageSources>
</configuration>

最新更新