Adventures of a wannabe geek!

Ranting within

PostSharp 2.0 and TeamCity Integration

This post is not in any way going to tell you what PostSharp is – you will need to check their website for a full explanation of what it is and what it can do. In a nutshell, I am using PostSharp for Attribute Based Caching in ASP.NET. In order to get this working there was 2 ways to deal with PostSharp.

PostSharp have a section about using the product on a build server as it needs a licence. This requires an install so that it can extend MSbuild to create the appropriate output. But I didn’t like this approach as I like to keep my build server as clean as possible from installs.

1. I could install PostSharp on the development machine and any other machine that will require to build the application (i.e build server).

2. I could try and use the PostSharp download in my solution tools folder and customise my .csproj file to hook into the MSbuild event. This is of course the path I took.

So I started by signing up to PostSharp and getting a licence key and downloading the source. I took the entire source and unzipped it to my lib folder inside my solution as follows:

image

This now means I have the source that is required. In order to ‘tap’ into this source I next need to change the .csproj file of the project that requires PostSharp use.  I have changed my .csproj to include the lines as follows below the Microsoft.CSharp.targets import:

<Import Project=”....\lib\PostSharp\PostSharp.targets” />

This imports a .targets file that is referenced in my lib in the PostSharp folder. This .targets file actually needs to have your licence key inside it if you don’t have an install of PostSharp locally. This means opening the .targets file in programmers notepad (or your favourite editor) and adding the following line just before the closing PropertyGroup tag:

(your licence key will be emailed to you when you join PostSharp)

<PostSharpLicenseKey>license key here</PostSharpLicenseKey>

When I checked my solution into source control and ran the build then my TeamCity build log showed the following information:

image

This basically means that PostSharp hooked into my build event to make the following code snippet actually work.

image

 

Any developer who works with this code will not require PostSharp installed on their machine and can work freely Smile