OK, so I try doing more with MSBuild … like: bumping the version number of my assemblies 🙂
So far so good – so let’s get startet. First of all you need to grab a AssemblyInfoTask extension for MSBuild. Just install it and you’re all set.
Next you have to modify your
*.csproj file. Just add:
to the end of the file. OK, this could already be all. But wait – what are all those errors in my newly build?
First I use subversion for source-control, so I have an addition
AssemblyInfo.cs somewhere in my
.svn folder-structure. This is not working with the AssemblyInfoTask :(. So navigate to your ‘$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.Targets’-file and edit it (with notepad or whatever). Then lookout for the
itemgroup defining the files to process and modify it to exclude any
.svn folders. This could look like this:
<!-- The items that get processed by the task --> <ItemGroup> <AssemblyInfoFiles Include="**\AssemblyInfo.*" Exclude="**\.svn\**\AssemblyInfo.*"/> </ItemGroup>
OK, for now you’re set – it compiles!! At least kinda. So next you’ll get some error about the version-number not being correct. Well no error without a fix :). There have been quite some discussions about this problem and a lot of various fixes. Well, Neil explains in his blog about why this is, and makes the point “So, I’m sad to say, we will be stuck with 16-bit build numbers forever.”. So this means no cure for this error.
OK, for me I just wanted to control the version number of my assemblies from outside visual studio. So I want to fix the version number. So I though adding the properties:
would do the trick. But far from right. I still would get at least incremented revisions. Looking at the code I noticed that:
would solve my problems. So my complete
PropertyGroup looks like this (with a version number of
126.96.36.199 for my Assembly, and
188.8.131.52 for my File-Version):
<PropertyGroup> <AssemblyMajorVersion>2</AssemblyMajorVersion> <AssemblyMinorVersion>1</AssemblyMinorVersion> <AssemblyBuildNumber>1</AssemblyBuildNumber> <AssemblyRevision>1</AssemblyRevision> <AssemblyRevisionType>NoIncrement</AssemblyRevisionType> <AssemblyBuildNumberType>NoIncrement</AssemblyBuildNumberType> <AssemblyFileRevisionType>NoIncrement</AssemblyFileRevisionType> <AssemblyFileBuildNumberType>NoIncrement</AssemblyFileBuildNumberType> </PropertyGroup>
You might notice that I don’t set the Assembly-File version in the
PropertyGroup. This is still managed from visual-studio (you don’t have to understand why I would wanna do this).