Search code examples
.netvisual-studio-2010version-controltortoisesvnassemblyversions

Visual Studio 2010 Setup to automatically change .NET project assembly versions from SVN versions


How can I specifically set up Visual Studio 2010 so I can automatically change the assembly version of my .NET projects without having to manually change them, during compilation (or building/rebuilding of a project/solution). Please be specific for how a typical company/organization would do this if they had a web application and multiple class library projects in the same solution. Let's assume we're using Tortoise SVN for version control and we want our project version to reflect the SVN version(s) automatically.


Solution

  • I'm not aware of any way to do this via Visual Studio.

    Does you organisation have a build script? I maintain a buildscript in Powershell, and from here the problem is quite solvable.

    Here's some example snippets:

    To extract the subversion revision number:

    $revisionNumber = (svn info $RepositoryPath -r HEAD | select-string '^Revision: (\d+)$').Matches[0].Groups[1].Value
    

    Then, to assign this version number to every assembly in the solution:

    $targetAssemblyVersion="1.0.3.{0}" -f $revisionNumber
    $assemblyDeclaration = "[assembly: AssemblyFileVersion(`"{0}`")]" -f $targetAssemblyVersion;
    get-childitem -recurse -filter "AssemblyInfo.cs" |
       % {
              $sb = new-object System.Text.StringBuilder;
              $_ | get-content |
               % {
                     $replacedString = ($_ -replace '^\[assembly: AssemblyFileVersion\("[\d\.]+"\)\]',$assemblyDeclaration);
                      $dummy = ($sb.AppendLine($replacedString));
                };
              $sb.ToString() | out-file $_.FullName;
        };