We’ve setup a NuGet Gallery and now we wanted to have our builds automatically package and publish to the NuGet Gallery.
The below is more or less the step-by-step process to get it up and running in an automated way.
Step 1 Create your NuSpec for your .csproj. The documentation on NuGet documents is pretty good for this step.
The gist is you will need to have the .nuspec file in the same directory as the .csproj file. You will have to modify this file and ensure you’ve populated all the correct tags as mentioned in the NuGet documents.
Note: An error message will appear when trying to package if something is missing.
Step 2 Modify your .csproj file and add the below snippets. They are generically written so they should fit right into your msbuild file fine. Obviously, edit when appropriate should your msbuild file already be customized.
Edit: Make sure you update the My_Nuget_Gallery_Service_Url token in the script to point to your gallery.
Note: You will need to run nuget setApiKey before this will work as it relies on the API Key for the NuGet Gallery already to be stored locally. This is handy as you can login as your Build Service Identity and run the command. It will then publish as that user from then on out.
Step 3 Run it via MSBUILD.
All you need to do on your build sever is execute the below command:
Edit: Make sure you update the tokens to be the correct values for your project.