Over the years I’ve been posting on the blog here at Wintellect a set of MSBuild tasks that make it easy to get the TFS Build number during a build and use it as your binary version string. You can read about that code here and here. In a nutshell, you modify your C#, VB, or C++ project and magically you have the build numbers. Link to the created files in your project and now your file versions match the TFS build number with easy to understand encoding for the build date. None of this requires anything on the server so you don’t have to mess with the nastiness of Windows Workflow in TFS Build.
Uber TFS master Brian Randell pinged me recently and asked if my Wintellect.TFSBuildNumbers would work on the hosted TFS. I love the idea of Hosted TFS Build, but every build I’ve worked on was too complicated for it so I hadn’t bothered to check. Well, when Brian asks, you can’t turn him down so I gave it a go and of course the builds failed because of access denied errors. The good news is that in about 15 minutes, I had everything working.
I also took the time to document everything inside Wintellect.TFSBuildNumbers.targets and create a new demo application showing how to integrate into a .CSPROJ file. It’s basically the same for .VBPROJ and .VCXPROJ files. Additionally, I tested everything between developer builds, TFS On Premises build server, and of course, TFS Hosted build servers.
Instead of posting on the blog again, I moved the whole project to Wintellect’s open source page at GitHub. You can grab the project directly at https://github.com/Wintellect/WintellectTFSBuildNumber. Please feel free to offer up a pull request and add additional version string file creation and project support. Everyone should have easy access to their build numbers from TFS!