Same Assembly Version For All Project

A question I was asked today was how to manage the same Assembly Version for several project I.e. have it managed in one place.

There are several way to accomplish this task... the most simple is as follows:

1 Delete the  AssemblyVersion and  AssemblyFileVersion attributes from the AssemblyInfo.cs file in all the target projects. ( this will remove duplication conflicts)

2. Create a new file to host the version (I've called it FileVersion.cs in this sample) and pate the following code into the new text file:

using System.Reflection;

// Set here the global file version
[assembly: AssemblyVersion("1.2.3.4")]
[assembly: AssemblyFileVersion("1.2.3.4")]

3. Here comes the tricky part... in each of your target projects you would want to add a link to the existing file, note on the word link and not just adding an existing file which will add a copy of the FileVersion.cs file to your project.

In order to add an existing file as link open the Add Existing File Dialog Box (Right Click on the project -> Add -> Existing Item) then choose the file (FileVersion.cs) and before hitting the Add button click on the small arrow on this button and choose add as link.

[ Click on the picture above to see it in large ]

4. Thats it... you have one place to maintain the file version.

3 Comments

  • But if you have a solution which includes both Web Application (Web service for example) and Class Library Project ? I think that you have to maintain both SolutionInfo.cs and AssemblyInfo... Do you know how to solve this ?

  • Wow, I cant believe I never knew that. I mean the option is so logically located in a ... drop down menu ... of a ... button. Thats some nice GUI design there ;)

  • I am wondering the same thing as Amir. How can you have both a web application and class library projects and maintain file version in one place?

Comments have been disabled for this content.