Building a SharePoint 2010 WSP Using TeamCity

I’ve been using Continuous Integration for years.  It’s been a part of almost every project I’ve worked on.  Prior to a few months ago, I was a CruiseControl.NET devotee, but recently a few of my colleagues expressed a preference for TeamCity.  I tried it, and now I’m a convert!

However, the Microsoft stack is not set up with CI in mind.  You’ll need to use a few tricks to set up your build on a computer which does not have a full dev environment.  This is particularly true when developing for SharePoint 2010 using Visual Studio 10.

Using TeamCity

Setting up TeamCity is pretty straightforward.  It’s a free product (up to 20 builds), and can be downloaded on the JetBrains web site.  I won’t go into the basics of TeamCity right now. However, once the product is installed, start by setting up a simple project with a version control settings, but no build steps – it simply downloads the code from your repository.

Preparing to use MSBuild

There are quite a few dependencies to satisfy, for a SharePoint build.  You’re using .NET 3.5, but you’ll want to make sure to use MSBuild 4.0 if you’ve been using VS2010. Features like WSP creation are not available in earlier versions.

Setting up dependencies

I used to do this step though trial and error, but recently found a great resource for this: http://msdn.microsoft.com/en-us/library/ff622991.aspx.  Follow the instructions in step 1. (Prepare the Build System).  Obviously we’re not using TFS here, so skip that step. This step outlines the dependencies, and instructs us on which dll’s we need to manually add to the GAC.  There’s a whole list.  The short explanation is that you copy the dll’s from your dev environment, and place them into the GAC the build server.

One “gotcha” here is that that you need to make sure you’re using the correct version of gacutil.exe when adding items to the GAC.  The reason is that .NET 4.0 adds a second GAC(!), so if you get the following message, you’ll know you have this problem:

Failure adding assembly to the cache:   This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.

On my machine, the path of the proper version of gacutil.exe was located in

C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\gacutil.exe

Make sure you are working from the most recent version of the Microsoft Windows SDK.   The following page should take you there: http://msdn.microsoft.com/en-us/windows/bb980924.aspx

Remember, YMMV here.  If you do not have SharePoint installed on your build machine, you’ll have to add any SharePoint dll’s necessary to build your project as well.  Anything that you miss will be readily apparent in the next step…

Adding your MSBuild step to TeamCity

Go back to the project you set up, and add a Build step.  Select MSBuild from the Dropdown. Your project should look similar to this:

image

Notice the Command Line Parameters setting.  IsPackaging=True causes the build to actually generate WSP’s for any of your projects that are configured to do so.  Without this parameter, a simple build will be performed.

Hope you enjoyed my first post!  Let me know how it goes.

Comments
  1. 5 years ago

Leave a Reply

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