- Download MSBuild Community Task
- Add the following to the .csproj file of the project you want to follow the svn build numbering. Add just before </Project>
<!-- Import of the MSBuildCommunityTask targets -->
<import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<!-- to manage version number -->
<target Name="Version">
<version VersionFile="version.txt" RevisionType="Increment">
<output TaskParameter="Major" PropertyName="Major" />
<output TaskParameter="Minor" PropertyName="Minor" />
<output TaskParameter="Build" PropertyName="Build" />
<output TaskParameter="Revision" PropertyName="Revision" />
</version>
</target>
<!-- to generate our personnal version info -->
<target Name="AssemblyInfo">
<svnversion LocalPath="$(MSBuildProjectDirectory)" Condition="Exists('$(ProgramFiles)\subversion\bin\svn.exe')">
<output TaskParameter="Revision" PropertyName="Build" />
</svnversion>
<assemblyinfo CodeLanguage="CS"
OutputFile="Properties\AssemblyInfo.cs"
AssemblyTitle="WindScanner"
AssemblyDescription=""
AssemblyCompany="Risø"
AssemblyProduct="windscanner"
AssemblyCopyright="Copyright © 2010"
ComVisible="false"
Guid="88812638-9547-4480-3bf4-4fe25103b35c"
AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)"
AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"
Condition="$(Revision) != '0' "/>
</target>
<!-- We launch these two targets -->
<target Name="BeforeBuild">
<calltarget Targets="Version" />
<calltarget Targets="AssemblyInfo" />
</target>
<target Name="AfterBuild">
</target>
Change the path of your svn installation if necessary.
You can now use stuff like
public static String Version
{
get
{
return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
}
}
And the the changes reflecting the svn build!

(4.90 out of 5)