More on TFS 2010 Build Numbers Inside Your Projects
The other day I wrote about how to incorporate build numbers into your .CSPROJ and .VCXPROJ files. In doing some more testing I found in some edge cases where the way I was getting the current build number by including Microsoft.TeamFoundation.Build.targets could interfere with the TFS Build. That’s not good so I fixed the problem by declaring and using the GetBuildProperties task by itself. That avoids the odd build case and makes everything work. I’ve updated the sample with the latest Wintellect.TFSBuildNumber.targets file so grab it here.
In my previous post I showed the simple example of changing the one .CSPROJ or .VCXPROJ file that’s built at the beginning of your build. I was working on a large system that was broken into multiple .SLN files that could be built in any order. That meant I had to edit multiple projects and wanted to show how I simplified the integration into many projects.
First I created a common ,Targets file I called VersionNumbers.Targets that included everything necessary for creating the version number files for both C# and C++ projects. The comments in the file explain what’s going on. You can use this file as the basis of all your version number files.
- <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <!-- The following two properties are mandatory with
- <!-- Assume the shared directory but allow it to be changed before
- before including this file. -->
- <PropertyGroup Condition=" '$(SharedVersionOutputDirectory)' == '' ">
- <!-- Include the targets that create the version number files. -->
- <Import Project="Wintellect.TFSBuildNumber.targets" />
- <!-- C# and VB projects are easy, I'll just jam in the file creation on the included
- BeforeBuild which will get everything hooked up perfectly. -->
- <Target Name="BeforeBuild"
- Condition="('$(MSBuildProjectExtension)' == '.csproj') Or ('$(MSBuildProjectExtension)' == '.vbproj')">
- <!-- Only use the named target if it's a C++ build, otherwise you get an MSBuild
- warning MSB4057 about an non existant target. -->
- <PropertyGroup Condition=" '$(MSBuildProjectExtension)' == '.vcxproj' ">
- <!-- For C++ projects, jam in the file creation before doing the Resource Compiler
- build. -->
- <Target Condition=" '$(MSBuildProjectExtension)' == '.vcxproj' "
Once everything is isolated into your VersionNumber.Targets file, you can include it with the following line in your .CSPROJ or .VCXPROJ file.
On Sep 11 2011 12:44 PMBy jrobbins
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <Import Project="..\Build\VersionNumbers.Targets"/>