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.
- possible duplicate of SVN Revision Version in .NET Assembly w/ out CC.NETLazy Badger– Lazy Badger2012-03-14 04:07:01 +00:00Commented Mar 14, 2012 at 4:07
- Isn't it best to merge rather than close? I read that somewhere on the meta site.JustBeingHelpful– JustBeingHelpful2012-03-14 04:39:23 +00:00Commented Mar 14, 2012 at 4:39
- 1. All good full answers already was written in mentioned question. 2. I haven't power of mergersLazy Badger– Lazy Badger2012-03-14 04:44:58 +00:00Commented Mar 14, 2012 at 4:44
- Merging can only be done by moderators, and is pointless in 99% of cases.Cody Gray– Cody Gray ♦2012-03-14 06:41:32 +00:00Commented Mar 14, 2012 at 6:41
Add a comment |
1 Answer
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; }; 4 Comments
JustBeingHelpful
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?
Andrew Shepherd
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.
JustBeingHelpful
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
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.