Search code examples
azure-devopsnugetnuget-package-restore

Nuget package from specific package source on nuget restore step on Azure


The package I am trying to restore is both on nuget.org and on a 3rd party myget. The 3rd party is a higher version (pre-release) that I want to use, however it seems to not even try to locate the myget source for this package since it finds the package on nuget.org except not the version I want resulting in the following error message:

##[error]The nuget command failed with exit code(1) and error(Errors in packages.config projects
Unable to find version '2.0.0-dev-00013' of package 'Discord.Addons.Interactive'.
  https://api.nuget.org/v3/index.json: Package 'Discord.Addons.Interactive.2.0.0-dev-00013' is not found on source 'https://api.nuget.org/v3/index.json'.)

The myget is properly configured in my nuget.config, which is in my solution root

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Foxbot" value="https://www.myget.org/F/foxbot-discord-addons/api/v3/index.json" />
  </packageSources>
</configuration>

How would I go about making the nuget restore step respect the myget package source for this package?


Solution

  • How would I go about making the nuget restore step respect the myget package source for this package?

    For nuget restore task, there's one option used to control which feeds to use during package restore.

    See feeds to use:

    enter image description here

    Different from restoring packages locally, the nuget.config file in solution directory(Devops Repos) won't work until we check the Feeds in my Nuget.config option.

    So during that process, nuget actually didn't use your nuget.config file for package source, which caused this issue:

    enter image description here

    Workaround:

    Configure the Feeds in my Nuget.config like below to make sure nuget will use your Nuget.config file in Solution directory:

    enter image description here

    In addition: If you're using yaml format instead of classic format, you should set feedsToUse: 'config' and nugetConfigPath: 'path/NuGet.config'.