Linking Tortoise SVN revision number to assembly version

I’m developing a program in C# .net in visual studio and version controlling it with tortoise SVN.

at present I’m creating the assembly version based on the build number.

  • What is the advantage of committing to the Git object database?
  • Reverting to a previous commit in Git for visual studio 2012
  • Visual Studio sometimes detects configuration issue on jenkins CI server
  • Since Repository Merge is not implemented yet, is there any alternative?
  • Best way to combine Git with .NET when versioning
  • How to partially stage a file with LibGit2Sharp?
  • Is there a way I can link the final part of a projects assembly version to the revision number in tortoise SVN instead, eg:

    pseudo code:

    [assembly: AssemblyVersion("1.0.0."+SvnRevisionNumber.ToString())]

    This would ensure that my assemblies were named after, not their build number, but after the last revision number committed to the repository.

  • Subversion with Continuous Integration
  • web.config and app.config machine-specific settings in git
  • “Mark” svn export with revision
  • How to Build Cpp code on jenkins?
  • How do I delete 1 file from a revision in SVN?
  • SubGit: use svn.svnCommitMessage option
  • 3 Solutions collect form web for “Linking Tortoise SVN revision number to assembly version”

    What I use is calling a cmd file at the post build event:

    @echo off
    if %1x==x goto ERROR
    SET ProjectDir=%1
    SET SubWCRev="C:\Program Files\TortoiseSVN\bin\SubWCRev.exe"
    if exist %SubWCRev% goto USESUBWCREV
    REM Default to copying a default version
    copy %ProjectDir%\Properties\AssemblyInfo.default.cs %ProjectDir%\Properties\AssemblyInfo.cs
    echo default
    goto END
    REM We don't want to modify AssemblyInfo.cs every time, only when a revision
    REM changes. Thus, we want to first compare the last compiled revision with
    REM the current revision, and only update if they've changed.
    %SubWCRev% %ProjectDir% %ProjectDir%\Properties\rev.subwcrev-template %ProjectDir%\Properties\rev.current.tmp
    if exist %ProjectDir%\Properties\rev.last-build.tmp goto CHECKREV
    goto NEWREV
    REM Fetch the current revision and compare to last-build revision
    fc %ProjectDir%\Properties\rev.last-build.tmp %ProjectDir%\Properties\rev.current.tmp > NUL
    REM Only update if it's a new revision
    if errorlevel 1 goto NEWREV
    goto END
    REM Current revision doesn't match last-build revision. Update!
    echo newRev
    if exist %ProjectDir%\Properties\rev.last-build.tmp del %ProjectDir%\Properties\rev.last-build.tmp
    copy %ProjectDir%\Properties\rev.current.tmp rev.last-build.tmp
    echo use template
    %SubWCRev% %ProjectDir% %ProjectDir%\Properties\AssemblyInfo.subwcrev-template.cs %ProjectDir%\Properties\AssemblyInfo.cs
    echo done
    goto END
    echo Usage: %0 project_dir
    echo For example:
    echo    %0 C:\projects\MyProjectDir
    goto END

    You can use something like this to get the svn revision number.

    <echo message="Retrieving Subversion command line: ${rvsnCommandLine} into ${deployment.SourceDir}"/>
         <exec program="svn.exe" workingdir="${deployment.SourceDir}" commandline='update ${rvsnCommandLine}' failonerror="false"/>
         <echo message="Retrieving Subversion revision number ${svn.revision}"/>
           commandline='log "${deployment.SourceDir}" ${rvsnCommandLine} --xml --limit 1'
         <echo message="Using Subversion revision number: ${svn.revision}"/>

    It pretty much outputs the svn revision to a xml file then xml peeks to get the revision number.

    You could perhaps use this as a pre-build event and then update your assemblyinfo with the new version number.

    Also check this thread for more info
    SVN Revision Version in .NET Assembly w/ out CC.NET

    I’d be looking into the MSbuild Extension Pack.

    There is a Subversion extension which will retrieve the SVN stuff for you automatically. Link here: MSBuild Subversion Extension Help

    Secondly you could then use that with other extensions to set the version of a directory programatically. Depending on your layout in your SCM system, you might be able to version each directory in it’s own repository like this.

    Git Baby is a git and github fan, let's start git clone.