Wednesday 5 May 2010

Update AssemblyInfo as part of the build process

I use TeamCity to build by code as part of continuous integration. One of the tasks I tend to do is to update the AssemblyInfo file with the current build number.

First you need to ensure you have installed the open source project MSBuild Community Tasks, downloadable from here.

Then the code to do this is:
<Target Name="PreBuildTasks">
<PropertyGroup>
<Version>$(BUILD_NUMBER)</Version>
</PropertyGroup>
<MSBuild.Community.Tasks.AssemblyInfo
CodeLanguage="CS"
AssemblyCompany="CompanyName"
AssemblyCopyright="Copyright (c) CompanyName2009"
AssemblyDescription="Description"
AssemblyFileVersion="$(Version)"
AssemblyVersion="$(Version)"
AssemblyTitle="Titlek"
Guid="1938930d-a5f3-4045-a5f3-f5b930d70ade"
AssemblyProduct="Product name"
OutputFile="$(MSBuildProjectDirectory)\ProjectName\Properties\AssemblyInfo.cs" />
</Target>

Please note this has only be tested to work on TeamCity.

No comments: