1

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:\a\1\s\HR Taxonomy Change Management\HR Taxonomy Change Management.csproj NU1101: Unable to find package Telerik.UI.for.Blazor. No packages exist with this id in source(s): C:\Program Files\dotnet\library-packs, NuGetOrg

Errors in D:\a\1\s\HR Taxonomy Change Management Tests\HR 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 Files\dotnet\library-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 2

2

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".

Sign up to request clarification or add additional context in comments.

Comments

1

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'

3 Comments

I added <guid> in place of the actual guid. Wasn't sure if exposing the full key/path/url was a security risk. Sorry I didn't clarify that. The suggestions you are making, relates to getting the nuget from the Azure Artifact? I'm assuming the VTS Feed in my nuget task points to the Artifact? maybe...?
Ok, then you maybe have to leave it in there. If I go to Artifacts -> Connect to feed -> NuGet.exe, I get an url without any guid in there. Did you try out reading the feed from the config like in one of the example tasks above though?
I looked it up again. The feed url can be of two different formats: for project scoped feeds: https://pkgs.dev.azure.com/<companyName>/<projectName>/_packaging/<feedName>/nuget/v3/index.json and for organization scoped feeds: https://pkgs.dev.azure.com/<companyName>/_packaging/<feedName>/nuget/v3/index.json . So I guess the guid in yours represents the project then. (For me, I can only see resolved names, but no guids. That is why i was confused.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.