Updating NuGet packages to the latest available version in VSO

Lately we’ve been using the new „Packages“-feature  of Visual Studio Online to manage our own NuGet-Packages. The feature rellay „kicks ass“ when integrating your own packages within your organization.
For starters Microsoft gives you a great How-To get started with Package Management in VSTS and TFS helping you setting up the package management and fetching your own NuGets with Visual Studio into your projects.

This article describes the manual steps to go and you need to manually update your version numbers each time you release a new package. To take this a step further you want to automate the creation of new packages and integrating them into your feed so you always have the newest version available within your team. Each time a build of a NuGet successfully completed you should automatically provide the new version to your team. Microsoft also provides a great How-To „publish NuGet packages from Team Build to Package Management“.

It’s all about automation – that’s where you get your value

Now we have been able to set up an automatic creation of new NuGet-Package-Versions that we can reference in our Visual Studio projects. But you may experience, that every time you get a new NuGet-version you also must update the version number in your project to actually get the new NuGet-package-versin.
For production deployment you might really want to carefully decide which NuGet version you reference in your project. But for some projects you might always want to integrate your solution in the test-environemnt with your newest available NuGet-Packages.

So, how can we accomplish keeping NuGet Packages up-to-date to the newest available version? In npm (Node Package Management) you can use semantic versioning to define you want to use the latest minor version release with e.g. ^2.0.6
But we do not have semantic versioning in NuGet. Instead we can use the command NuGet update.

Configure Visual Studio Online Build-Task to update NuGet packages

The following screeshot shows the configuration of a Visual Studio Online Build-Task to update a defined package of a solution to the newest NuGet-package-version:

NuGet update in VSO

Edit your build-definition and add the „NuGet“-Task to it.

Select version 2.* of the NuGet-Task. Select „custom“ as Command. Having selected these options lets you define custom NuGet-Commands. (all available custom commands). Now you can insert the NuGet update command to fetch your newest NuGet packages:

update $(Build.Repository.LocalPath)\{Name of your solution}.sln -Source "{Package source URL}" -Id {Package Id}

{Name of your solution}: quite obvious. 😉

{Package soure URL}: you can find your package source URL in Visual Studio Online -> Build and Release -> Packages -> Connect to Feed -> Package source URL

{Package Id}: as package Id you can use the package title. You can find it in Visual Studio Online -> Build and Release -> Packages -> Package (title-column of the table)

Save your settings and that’s it. You’re ready to roll 😉

Happy coding.

Schreibe einen Kommentar