Publish to Private NuGet Repo from VSTS

NuGet is an outstanding dependency package management platform. The integration within Microsoft Visual Studio makes managing these packages extremely simple. One of the things I like the most about NuGet is that I don’t have to commit all of my dependencies into a source control repository. I have started using a private company hosted NuGet repository sitting behind an SSL endpoint with Active Directory security so we can securely manage our own packages for internal and client projects. In the beginning we were also hosting our own Team Foundation Build servers on our own premises.  This worked really well and didn’t provide any issue with security because our NuGet server and build server was on the same domain.  However, recently we started moving to Microsoft Visual Studio Team Services (VSTS) in the cloud.  The problem arises now because our NuGet server is still hosted internally on our domain but VSTS and it’s build services are now in the cloud and don’t have direct access to our NuGet server.

NOTE: Your NuGet server must be exposed externally outside your firewall.

Step 1: Inside of your build process within VSTS, you need to add a NuGet task to add a new NuGet source.  Set the “Display name” to something that represents adding a new NuGet source.  Set the “Command” to “custom”.  Add the following command in the “Command and arguments” text box:
source add -name “” -source https://%5BNuGet Server Endpoint]/nuget -username “[domain]\[username]” -password [password]


Step 2: Inside of your build process within VSTS, you need to add a NuGet task to create the package you are going to upload to your repository.   Set the “Command” to “pack” and select the “Path to csproj or nuspec file(s) to pack” to the path within your repository you have saved your .nuspec file.  If you aren’t familiar with creating a nuspec file see the Creating NuGet packages.



Step 3: Inside of your build process within VSTS, you need to add a NuGet task to push the package to your private repository.  Set the “Command” to “push”.  Select “External NuGet server (including other accounts/collections)” for the Target feed location.


Once you have the task created, you need to configure an external “Endpoint”.  Inside the task you just created, click on “Manage” next to NuGet server.  This will launch a new page that allows you to configure a new external site connection.  Click the “+ New Service Endpoint” button.  This will launch a dialog for you to enter the information for your private repository.  Add the same endpoint URL that you added to the source command in Step 1 and add the custom API key that is configured on your NuGet server.


Then back on your build step, select that new endpoint from the drop down.  That’s it and you should be able to now package and publish to your private NuGet repository assuming it’s exposed externally.