Embedding SVN revision number at compile time with MsBuild

You may also like...

  • Anonymous

    We had to use RevNr / 10000 . REvNr % 10000 on the last 2 parts of the Versioning because of Revisions up and above of 10k.


  • Jens

    Ist also possible to get the LastChangedRevision instead of the revision.?

  • Camilo

    Hi Zoran,

    I’ve tried to do this but i don’t have svnVersion.exe. I’m using tortoise SVN 1.7.

    Thank you!

  • Paul

    Hi Zoran,

    I get the message:
    Revision: 27210
    Updating File “c:\work\Projects\trunk\Gr\Lisp\Prac\MyProject\Properties\AssemblyIn
    Replaced matches with “$1.$2.$3.27210”.

    but I see no changes in the AsseemblyInfo.cs:
    [assembly: AssemblyVersion(“”)]
    [assembly: AssemblyFileVersion(“”)]

    What is wrong?


    • Hi Paul,
      If this runs on a CI server, this process won’t commit the file (AssemblyInfo.cs) back to SVN and I guess that this is why you don’t see any difference.
      But, if you run this from your workstation you should definitively see the AssemblyInfo.cs changed.

      • Paul

        Regex should be:


  • d4l1b0r

    Nice post!

    We use MSBuild Versioning (versioning.codeplex.com) to perform the pre-build processing.

    At the end the build date information is in the 3d group and the svn-revision number in the 4th digit group, as in your case. Since our revision numbers are still low enough (3 digits), we use the 4th digit to signal commit status. If the assembly was built using non committed code (dirty) it ends with 1, otherwise wit 0.


    • Hi Dalibor,
      I checked the versioning.codeplex.com that you mentioned, and indeed is a good tool and probaly we will try to integrate it. I think that the solution here expressed mimics pretty much what that tool does.
      I have to add that what I’ve described in the above post, works well when it comes to run the process in an CI environment. I noticed one small annoyance when building the solution on the workstation. Before the compilation starts, the assemblyinfo.cs is changed, and then code get’s compiled. What is missing in this process is to re-change again the AssemblyInfo.cs files to what they’ve been before the compilation process, otherwise you have to delete those files manually and reload them from SVN. Nothing serious but worth investigating.


febles.scarlet@mailxu.com brassard@mailxu.com