Alan Díaz
Alan Díaz

Reputation: 113

How to install a nuget package from another package source in azure devops pipeline?

I'm trying to run some API test on azure, I've been able to run my artifacts before, but this specific task requires a package that is not in package source: nuget.org, it is a package from the company I work for, so when I run the pipeline i get this message:

##[error]The nuget command failed with exit code(1) and error(NU1101: Unable to find package: name of package

I ran with this problem when creating my project so I had to add the package source, how can I do this on the pipeline?

Upvotes: 9

Views: 5550

Answers (3)

Stelios Giakoumidis
Stelios Giakoumidis

Reputation: 2283

Assuming form your question tags that you use azure devops, you have to set in the yaml file, the restore task like this:

- task: DotNetCoreCLI@2
  displayName: 'Restore Nuget Packages'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: '<your key>'

Upvotes: 1

VishwajeetMCA
VishwajeetMCA

Reputation: 147

If the package you are talking about is custom package that you have created, then you need to first push the nuget package to Azure Artifact and then you can configure Azure DevOps pipeline to restore the package from Azure Artifact.

Upvotes: 0

Simon Ness
Simon Ness

Reputation: 2550

You can place a nuget.config file at the solution level that lists the package sources, e.g.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="your-nuget" value="https://pkgs.dev.azure.com/example/_packaging/example-nuget/nuget/v3/index.json" />
    <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>

Note that this should work for Visual Studio too (you should be able to remove the extra package source if you added manually via the VS Tools menu).

Then depending on your flavour of .net it's just a case of having a step to restore the packages before the build, DotNetCoreCLI@2 (command: restore feedsToUse: 'config') or NuGetCommand@2 (command: restore feedsToUse: 'config').

Upvotes: 9

Related Questions