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

时间:2017-02-13 15:26:41

标签: docker asp.net-core nuget ubuntu-14.04 .net-core

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

dotnet restore

在Ubuntu上,公共NuGet repo下载的软件包下载很好,但Artifactory上的软件包失败了:

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

我在\home\<user>\.nuget\NuGet\NuGet.Config找到了一个N​​uGet配置文件,并添加了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>

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

NuGet本身在安装.NET Core SDK后不起作用,我正在使用dotnet restore如上所述 - 我是否必须为dotnet CLI编写类似的配置(必须使用NuGet?)或者有什么东西否则我需要做什么?

谢谢!

2 个答案:

答案 0 :(得分:7)

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

  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.
    
  3. 原来我们的Artifactory NuGet repo返回符合NuGet v2的XML。我更改了配置文件,将repo设置为v2,现在正在运行。因此,从上面开始,在

    编辑文件
    \home\<user>\.nuget\NuGet\NuGet.Config
    

    添加新的repo网址,并获得正确的版本设置:

    <?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>
    

答案 1 :(得分:6)

Dotnet CLI恢复可以将-s作为源Feed网址,因此如果您将Artifactory与Remote repository存放到nuget.org。

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

参考: