skip to Main Content

I am creating my first Azure pipeline and I’m running into trouble getting it to restore a Nuget package from Azure Artifacts. I have a default Yaml file and I added a Nuget Task which is supposed to point to my Artifact instance

- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'Telerik'
    vstsFeed: '<guid>/a765533f-c8a7-49aa-9b83-adcf9b945be9'
    includeNuGetOrg: false

There’s also the default task to restore packages

- task: NuGetCommand@1
  inputs:
    restoreSolution: '$(solution)'

I created a Nuget.config file in the project root, with the .sln file

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="Telerik" value="https://pkgs.dev.azure.com/OneHRADO/<guid>/_packaging/Telerik/nuget/v3/index.json" />
  </packageSources>
</configuration>

Its throwing errors for my two projects

Errors in D:a1sHR Taxonomy Change ManagementHR Taxonomy Change Management.csproj
NU1101: Unable to find package Telerik.UI.for.Blazor. No packages exist with this id in source(s): C:Program Filesdotnetlibrary-packs, NuGetOrg

Errors in D:a1sHR Taxonomy Change Management TestsHR Taxonomy Change Management Tests.csproj
NU1101: Unable to find package Telerik.UI.for.Blazor. No packages exist with this id in source(s): C:Program Filesdotnetlibrary-packs, NuGetOrg

I have a suspicion its getting to the first Nuget task and it can’t find the packages that are in the Artifacts and its failing.

Here is my artifact
enter image description here

Update: Still ‘no joy’. I tried your suggestions @johnmoarr and no change. I tried removing each of the nuget (or dotnetcli) commands and switching the order. I determined one thing for sure. The ‘basic’ nuget command tries to get everything from nuget.org, including the Telerik package and so it fails. If I put the Artifact nuget command first, it fails for everything else.

I have ready online that you can put multiple sources in your nuget.config file like so:

<configuration>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Telerik" value="https://pkgs.dev.azure.com/OneHRADO/33581106-1fd6-4092-9693-a20196c22142/_packaging/Telerik/nuget/v3/index.json" />
  </packageSources>
</configuration>

I think my company has some internal scan and threw an error for this believing its a security risk to have two https sources.

I’ve been looking for a way to exclude packages so nuget command #1 won’t try and restore what’s in my Artifact but no luck yet.

2

Answers


  1. Chosen as BEST ANSWER

    I finally figured it out. Not sure if this is the "right" answer or not, but it works. I had to set up an Upstream Feed for Nuget.org in my Artifact feed. Once I did that, it downloaded all the nuget stuff it needed for the build, so the feed is the single source for the build.

    To set up the feed, click on Feed Settings (gear in top-right of window) and select the "Upstream Sources" tab. Click on "Add Upstream" > "Public Source" > "NuGet Gallery".


  2. Not sure where the <guid> part in your feed url is coming from. I don’t see one in any of our feed urls.

    I would try changing it to .../OneHRADO/_packaging/....

    Apart from that, the nuget.config looks fine.

    For the restore, I mostly use a dotnet task. So from my perspective, this should work:

    - task: DotNetCoreCLI@2
      displayName: "Restore solution"
      inputs:
        command: 'restore'
        projects: 'RepoName/path/to/Your.sln'
        feedsToUse: 'config'
        nugetConfigPath: 'RepoName/path/to/nuget.config'
    

    If you want to stick with the NuGetCommand for restore though, I think this might also work (can’t test it at the moment)

    - task: NuGetCommand@2
      displayName: "Restore solution"
      inputs:
        command: 'restore'
        restoreSolution: 'RepoName/path/to/Your.sln'
        feedsToUse: 'config'
        nugetConfigPath: 'RepoName/path/to/nuget.config'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search