26

I am running .NET Core 1.1.0 on Ubuntu 14.04, with the goal of hosting my Web APIs in Docker on Ubuntu. I want to build my packages on Ubuntu, but some of the NuGet references are hosted on an internal NuGet repository (Artifactory). This works fine in VS2015 on Windows after I add the package source, but when I run:

dotnet restore

on Ubuntu, the packages hosted on the public NuGet repo download fine, but those on Artifactory fail:

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

I found a NuGet config file at \home\<user>\.nuget\NuGet\NuGet.Config and added the Artifactory repository as follows:

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

but I am still getting the same error.

NuGet itself does not work after installing the .NET Core SDK, I am using dotnet restore as mentioned - is there similar config I must edit for the dotnet CLI (which must be using NuGet?) or is there something else I need to do?

Thanks!

Peter
  • 5,455
  • 7
  • 46
  • 68

2 Answers2

20

Dotnet CLI restore can take -s as source feed url, so if you have Artifactory with Remote repository to nuget.org.

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

Reference :

JosephKumarMichael
  • 971
  • 1
  • 7
  • 9
16

After all that I quickly identified 2 problems I had missed:

  1. I had used sudo -i to run as root attempting to resolve the problem, as as a result the NuGet config I setup in my \home folder was not being picked up.
  2. Moving back to my own logon, I then got an error:

    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.
    

Turns out that our Artifactory NuGet repo returns XML which is NuGet v2 compliant. I changed the config file to set the repo as v2 and it is now working. So, from above, edit the file at

\home\<user>\.nuget\NuGet\NuGet.Config

adding your new repo URL, and get the version setting right:

<?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>
Peter
  • 5,455
  • 7
  • 46
  • 68
  • 2
    You may also find the new dotnet cli support for adding nuget packages helpful: http://ardalis.com/how-to-add-a-nuget-package-using-dotnet-add – ssmith Feb 14 '17 at 13:45
  • 2
    That is worth knowing, although here I was asking about adding a new package source; i can see myself using dotnet add though, thanks. – Peter Feb 14 '17 at 15:14
  • 1
    Thank you so much! Here it is 4 years later, and the NuGet Package Manager Settings dialog, in which you add and remove custom repositories, _still infuriatingly hides_ this `protocolVersion` field. A default installation comes with one entry for the public nuget.org repo, _but with the protocolVersion pre-set to 3_, so if you open the dialog and just use the "Update" button to _modify_ that one entry to your internal URL, but your repo software only does version 2, it will fail and you'll have no idea why! Use the "X" button to delete that default one and then "+" button to make one afresh. – Jeff Saxe Jul 16 '21 at 21:34