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.

4
  • possible duplicate of SVN Revision Version in .NET Assembly w/ out CC.NET Commented Mar 14, 2012 at 4:07
  • Isn't it best to merge rather than close? I read that somewhere on the meta site. Commented Mar 14, 2012 at 4:39
  • 1. All good full answers already was written in mentioned question. 2. I haven't power of mergers Commented Mar 14, 2012 at 4:44
  • Merging can only be done by moderators, and is pointless in 99% of cases. Commented Mar 14, 2012 at 6:41

1 Answer 1

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; }; 
Sign up to request clarification or add additional context in comments.

4 Comments

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?
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.
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).
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.