Second point from the accepted answer is quite simple and provides desired result: output revision number somewhere within the application UI:
Use SubWCRev.exe with some custom code (script) in your build process
to insert the value into your file(s).
1) Think about what Assembly attribute to use and comment/remove its line in one of your projects' AssemblyInfo
file (I have chosen a "common" project and AssemblyFileVersion
attribute). Certain limitations may apply to various assembly attributes based on msbuild version as indicated here.
2) Create a template for use to generate the whole version. E.g.: SolutionInfo.cs.tmpl
using System.Reflection;
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyFileVersion("1.0.0.$WCREV$")]
// [assembly: AssemblyVersion("1.0.0.$WCREV$")]
3) Create actual file to be used to store generated version. E.g.: SolutionInfo.cs
. This can be empty, as it will be automatically generated on build. After build, it should like this:
using System.Reflection;
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyFileVersion("1.0.0.16788")]
// [assembly: AssemblyVersion("1.0.0.16788")]
Make sure to ignore/exclude this file from source control.
4) Create prebuild event to fetch revision number and create the file from its template:
"C:\Program Files\TortoiseSVN\bin\subwcrev" "$(ProjectDir).\.." "$(ProjectDir)\Properties\SolutionInfo.cs.tmpl" "$(ProjectDir)\Properties\SolutionInfo.cs"
Note: This build event assumes subwcrev is installed by TortoiseSVN in its default path. Build server must have the same configuration, so that build does not crash. If subwcrev
is registered in PATH
, the full path is no longer necessary.
5) Version fetch
public static class VersionExtensions
{
public static string GetFileVersion(this Assembly assembly)
{
var value = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
.OfType<AssemblyFileVersionAttribute>()
.SingleOrDefault();
return value != null ? value.Version : "?.?.?.?";
}
public static string GetCommonFileVersion()
{
var assembly = Assembly.GetAssembly(typeof(Common.Web.VersionExtensions));
var value = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
.OfType<AssemblyFileVersionAttribute>()
.SingleOrDefault();
return value != null ? value.Version : "?.?.?.?";
}