Adding custom feed to the VS build pipeline

When working with build pipelines, you might sometimes want to include your local nuget packages into the build process. To do this, you will typically create the nuget package in the root of your solution. Here is one example:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<packageSources>
		<add key="Local" value="nuget" /> 
  </packageSources>
</configuration>

When run the build process in VS all will work fine. This nuget package source will be added to the list of existing sources previously configured in VS settings.

Unfortunately, this will not work in the build pipeline of VS online. Pipeline will fail with the following error:

The nuget command failed with exit code(1) and error(NU1101: Unable to find package

To fix this, you will have to use following YAML configuration in the pipeline:

- task: NuGetCommand@2
  inputs:
   feedsToUse: 'config'
   nugetConfigPath: './NuGet.config'
   restoreSolution: '$(solution)'

This will work fine, but it will not find any other publicly available package in the nuget.org. Pipeline will fail again :(

To fix this issue, you need to extend your nuget.config. Add in there all required sources. This is required, because build pipeline uses a slightly different approach than VS build process.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<packageSources>
		<add key="Local" value="nuget" />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />    
  </packageSources>
</configuration>