Setting up TeamCity as a native NuGet Server

TeamCity 7.0 EAP (Early Access Program) was recently opened and one of the new features is the built-in support for NuGet. I recently blogged about setting up TeamCity to pack and publish NuGet packages via a plug-in and this plug-in is now included by default in TeamCity 7. However, the real new interesting feature is that TeamCity is now a native NuGet repository too!

Native NuGet Server?

Many of those that have been using NuGet, have most likely been using it to consume packages from nuget.org where there are currently over 3800 unique packages, most of which are open source.

image

What happens however if for some reason or another you do not want to submit packages to nuget.org? For instance, think that you want to use NuGet to modularize and distribute code inside your own organization, or create libraries for private consumption. In this case, publishing to nuget.org does not make sense. This leaves you with basically two options:

  1. Setup your own NuGet repository by downloading and installing the code that nuget.org for instance
  2. Copy nuget packages to a local share and have everyone read off of that

Both of these options come with their own share of overhead. With the local share you now require sharing of folders and permissions. Setting up your own NuGet repository also requires managing permissions and whatnot separately. At the end of the day, its another service to manage.

Fortunately, you now have a third option: TeamCity. The same server that builds your projects, runs your tests, packs and publishes your packages can now also serve them. The best part of it is that it is so simple, that I had to take up the rest of this blog with the previous nonsense just to give it some meat.

Enabling TeamCity as a NuGet Server

I am not going to cover how to pack and publish packages in this post. All that is covered in detail in the previous post I wrote, so please read that first if you’re not familiar with the process. Enabling TeamCity as NuGet and making packages available consists of two steps:

1. Enable the server to be a NuGet server

Go to Administration | Server Configuration | NuGet tab

image

Click on the Enable button to enable it. The same screen with then display two different feeds: a public and a private one:

image

If by chance the Public Url is not available, you will probably see a message telling you that you need to enable the Guest account in TeamCity, which can be done from the General tab.

2. Make your packages be your Artifacts

Since TeamCity itself is going to be a NuGet server, the step to publish a package is no longer required. However, packing the package is. In this step (NuGet Pack Build Type), we can just configure the output for the package to point to some specific folder, for instance packages

image

We need instruct TeamCity to ouput the results of this folder as artifacts. This is done in the General Settings step of the Build Configuration

image

and with that, we’re done. Next up is to configure Visual Studio to consume from this feed.

Configuring Visual Studio

Although this step is optional, it is recommended to add your repositories to Visual Studio to avoid having to type long URL’s in each time you want to read from a specific package repository. To do this, click on Options | Library Package Manager | Package Manager Settings

image

We need to add a new NuGet Repository. I’ve called it Local TeamCity and the URL corresponds to the public URL provided to me by TeamCity in Step 1:

image

Notice that I have another entry which is Local TeamCity Auth which corresponds to the authenticated version.

Once we have this, we can now easily consume packages from our repository by merely specifying it in the Package Manager Console, either via the Combobox or explicitly in each call:

image

Summary

That’s all there is to it. By merely publishing our packages as artifacts, TeamCity now provides a full-fledged nuget server which opens up great possibilities when it comes to working and managing dependencies between projects. TeamCity is currently in EAP and much of what I’ve described here is in open to improvements. That is why your feedback is very important. Download 7 and start playing with it today. Let us know what you think.

This entry was posted in Tips&Tricks and tagged , . Bookmark the permalink.

9 Responses to Setting up TeamCity as a native NuGet Server

  1. NotMyself says:

    We did something like this where I worked last year having TeamCity drop NuGet packages in a directory used by a home rolled Nuget server based on the Nuget.Server package. It worked awesomely, allowing us to have dependencies on truly open source projects like Castle and NHibernate and publish our own internal libraries in the same way. Having this baked into TeamCity is awesome!

  2. ChrisTTian667 says:

    Nice job!!!! Can’t await the stable version of TC7.

  3. thedersen says:

    As NotMyself says, we are also using TC to publish packages to our internal NuGet server. This will be much simpler! Awesome stuff.

    Will TC also be able to act as a symbol source server? That would be even more awesome:=)

  4. Hadi Hariri says:

    @thedersen

    That’s something we’re looking at but we can’t give say right now of what version it would be included in.

  5. Scott Koon says:

    Will we be able to specify non-project related packages in the TC NuGet server? We often need to maintain an older package for our internal use if it disappears from the official NuGet server.

  6. Eugene says:

    We do not plan to support it explicitly. The workaround is to create a build configuration that publishes those packages as artifacts. As packages are found in build artifacts thay will be accessible in the feed.

  7. Harry McIntyre says:

    Trying to update Nuget.exe inside teamcity, but there is no option to get v1.6. How do I install it manually?

  8. Eugene says:

    Harry,
    please try the workaround shown for http://youtrack.jetbrains.net/issue/TW-19365.

  9. Harry McIntyre says:

    Those instruction didn’t make much sense on my Window machine (couldn’t find the paths), but I just used the custom Nuget.exe option so all is well! Thanks Eugene

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">