Rake a NuGet

A few months ago I wrote about leveraging Albacore with Rake in a .Net project for doing things like building the solution, running tests, migrating the database, etc. Today I will explore one other thing that can be achieved with Albacore: NuGet.

There are 3 steps needed to publish your NuGet: first you have to create the nuspec, then pack the files based on that, then push the package to a NuGet server (private or public).

With Albacore, you can do all of these steps in code.

Let’s see how to do that assuming you have 2 packages you want to publish, one of which with a dependency on the other. You will need to have the NuGet command line tool installed on your machine.

First, you need to get the version for the various projects. You could read each project’s AssemblyInfo to get it, but in a solution with multiple projects it is usually better to use a global assembly info. I’ve also created a pack and push method that I can re-use.

Et voila! Now I can just run rake push and it will publish my packages. Assuming you integrate it with TeamCity and that you update the global assembly info with the build number on each build like I do, you won’t be getting duplicate version errors. Also note that you can get Team City to do a lot of these things for you, although I could not get it to properly create the dependencies without handwriting/generating my own nuspec

Rake a NuGet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s