Why would I want to restore local nuget packages?
Please note that it is recommended to pack and publish all packages and reference them by adding the URL as a new packageSource in your Nuget.config
With that out of the way, there might be times when you have local .nupkg
packages and wish to restore these packages during the build stage in your Azure pipeline. In my case, I had to quickly setup Azure pipeline for a client and they were still figuring out their private nuget package repository, so I set it up in such a way that it was possible for them to add the new package repository URL when they were done.
What problems will I encounter?
For the purpose of this article, I’ll be using the azure-pipeline.yml
file method (instead of the GUI method). In your azure-pipeline.yml
file, you might have something that looks like this:
With the above, if you only have referenced packages from api.nuget.org, the build pipeline should run fine. However, the moment you add references to local packages, you’ll get an error that looks like this:
error NU1101: Unable to find package Company.Connect.Shared.Logging. No packages exist with this id in source(s): nuget.org Build failed
How can I solve the problem?
That’s why you’re here, right? To solve this problem, you need to add an extra step to your azure-pipeline.yml file called the the Restore
step before your Build
step. Now your azure-pipeline.yml should look like this:
With this, your Azure pipeline first does a dotnet restore
fetching all packages including the local ones before going ahead to build
. At this time, during build, the local packages will then be available.
Thanks for reading :D
Top comments (0)