0

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.

JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245

1 Answers1

1

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;
    };
Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205
  • we use Cruise Control for our continuous integration. I think it just calls msbuild (standard .NET compile/build command). But I do know Cruise Control kicks off another build every time code is committed to SVN, so we could do exactly what you're doing during that build. So the revision number is the 4th number in the version? What do the first 3 numbers mean? – JustBeingHelpful Mar 14 '12 at 04:37
  • 1
    I just picked the first three numbers arbitrarily. With version numbering, the higher-significance digits tend to be based on marketing decisions rather than technical ones. – Andrew Shepherd Mar 14 '12 at 04:39
  • I see www.codeplex.com uses the year for the first version, then the 2nd and 3rd are based on the month and day-of-month of the last minor release (I think), and the last part must be the revision from Team Foundation (or version control tool). – JustBeingHelpful Mar 19 '12 at 15:33
  • 1
    I'm worried about the assembly version string in Visual Studio... it only allows a 16 bit number (max = 65535), which means we can't really use the Tortoise SVN revision number for this because the numbers will get too large. – JustBeingHelpful Mar 19 '12 at 15:47