简体   繁体   中英

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?

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

<?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').

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM