1. 程式人生 > >Get started with private NuGet feeds in Azure DevOps

Get started with private NuGet feeds in Azure DevOps

Okay we’re almost half way there. Now it’s time to define our NuGet tasks. .NET Core is pretty awesome and is able to deal with NuGet feeds out of the box, both when it comes down to restore and to publish packages.

Select the fifth .NET Core task, rename it to “Pack” and select the “pack” command. Make sure to set the appropriate options as seen here:

You may go for a different automatic package versioning scheme, it fully depends on your workflow and your preferences. You can choose between date and time, an environment variable or the build number. If you turn it off, it’ll use your version number from your project instead. Make sure to keep it up to date just to prevent any build errors or version conflicts upon publishing your feed.

Almost there, now it’s time to push the package. Select the last .NET Core task, rename it to “Push” and select the “nuget push” command.

Specify the path ($(Build.ArtifactStagingDirectory)/*.nupkg in our case) and select the feed location. Your feed that you created at the start of this article should appear in the list.

Select it. Boom, done.

Finally, let’s publish the artifact to our Azure DevOps project at the end of the build. Select the Publish Build Artifacts task. You may leave it as it is, it works just fine with the default settings.

Now we’re done. Save and queue your build definition and see the magic happen.

Consume your private NuGet Feed

Go back to the Packages area in Azure DevOps, select your feed and hit “Connect to feed”. You’ll see some instructions for your feed, but it’s fairly simple to set up.

Just copy your package source URL, go to Visual Studio, open the NuGet Package Manager, go to its settings and add a new source. Choose a fancy name, insert the source URL. Done.

Search for your package in the NuGet Package Manager and it should appear there, ready for installation. Make sure to select the appropriate feed (or just all feeds) from the top right select box.

That’s it

Next time we’ll give permissions and some minor features a poke.Have fun using your custom packages!