If you have a nuget packages that you deploy from your source code and want to move to the TFS 2015, there are good news. Packing and publishing nuget packages is fully supported in vNext build definition. Let’s see how to achieve that.
The goal is to pack the nuget package from a .csproj project file, create the .nupkg and then publish it to the nuget server. Let’s go to the TFS web portal and open the build definition for edit. Go to build steps tab and add two new build steps from the Package section.
First step is called Nuget Packager and should run just after the main solution build. Set its parameters as follows, selecting the proper project from your repository:
The nuget package will be compiled from your project file and put in _NugetPackages sub directory of the staging root. Note that if we build the nuget package from the project (.csproj) file instead of .nuspec file then the NuGet.exe tool (which is obviously used here) expects the compiled dll’s under the /bin/Release/ directory. This is important if you define an output directory in your main solution build step, since then there are no compiled dll’s in place which can be grabbed by the nuget packager. Unfortunately there is no option to tell the packager to pick up the binaries from somewhere else, so we have to keep in mind to build the solution in place.
In Advanced section I’ve also provided the build configuration variable which is used by the msbuild step, so the packager picks up dll’s from the proper directory no matter if this is Debug, Release or anything else. As the NuGet Arguments I also provide another variable which holds the package version. All build scoped variables can be configured in separate section called Variables.
The next step is the Package Publisher
This time your compiled nuget package is picked up from the staging directory and pushed directly to the nuget server to be available to download. You have to define you nuget server endpoint first so it is available for selection. In the Nuget Server Endpoint click Manage on the right side and you should be redirected to the control panel for you team project. Create the server endpoint as follows
Leave the user name blank and as a password type in your nuget server api key. Note that the nuget server ulr is different when you want to download the packages and when you want to publish the packages. Here you have to type in the short url without the /nuget/ at the end. Otherwise you will get following error message from the package publisher step:
When you are done hit ok and you can go back to your build definition. Save it and queue new build. If everything went ok, you should get your nuget package available to download right on your nuget server.