Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 499
Alan Díaz Avatar asked May 11 '20 02:05

Alan Díaz


People also ask

How do I install NuGet from another project?

You should have your required nuget packages listed in packages. config, and then just Restore them from nuget, which will download them and put them in the packages directory. So if I copy and paste the packages. config file from my old project to new project.

How do I add NuGet package to Azure pipeline?

Navigate to your classic pipeline definition, and then select Edit. Select + to add a new task. Search for NuGet, and then select Add to add the task to your pipeline. Name your task and select Restore from the Command.

How do I add a NuGet package to Azure DevOps artifacts?

Connect to feedSelect Artifacts, and then select your feed from the dropdown menu. Select Connect to feed. Select NuGet.exe. Follow the instructions in Project setup to set up your nuget.


1 Answers

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

like image 98
Simon Ness Avatar answered Oct 18 '22 05:10

Simon Ness