I spent long enough trying to search for solutions to automatically increment our Web site’s version number in Visual Studio Online, that I thought I’d write a step by step guide on how to accomplish this task.
First, thanks to John Robbins who actually is the brains behind the solution, I just wanted to supplement it with a succinct implementation plan.
Our application is an MVC Web application that is hosted and built utilizing Visual Studio Online.
- Download the latest version of WintellectTFSBuildNumber from GitHub.
- Extract the .zip file (if you downloaded the zip) to a desired temporary location.
- After you have extracted the .zip file, place the ‘build’ folder which contains two target files in your source control repository. This file should be placed outside of our solution. I placed this at the same level as my .sln file in my source tree. (e.g., /dev/build/)
- Modify the VersionNumber.Targets file in your /build directory to specify where the newly created files that will store your version info. I put these in the same build folder so it looks like this:
- Now I actually had a problem with the hard coded <TFSBuildRevision> that was hardcoded for local builds, so I went ahead and changed the following line in the Wintellect.TFSBuildNumber.Targets file to use a wildcard ‘*’:
<!-- For local builds from a developer, just grab the current date.—>
- I also wanted the output files to change both the AssemblyVersion AND the AssemblyFileVersion (I think by default it was just outputting the AssemblyFileVersion). To do this, I modified the Wintellect.TFSBuildNumber.Targets file to use the following lines (by default it just had the AssemblyFileVersion line).
- Since I only cared about this in our C# solution, I only modified the above lines under the comment
<!– The C# version file target. –>
- From this point, I went ahead and included the following lines in my .csproj file.
<Import Project=”..\Build\VersionNumbers.Targets” />
- At this point, we’re almost done. I opened up my solution and performed a build. This build output a bunch of the version files to the /build directory we created in step 3.
- I then added the file, SharedAssemblyFileVersion.cs, as a LINK from the /build directory into my solution. Note, you do not want to simply add this as an existing item to your source control. Ensure you add it as a linked item.
- That’s it! Now to reference this item programmatically, you can utilize System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();