Jan Schreuder on .Net

.Net code samples, experiences, observations

View my professional profile on LinkedIn

Recent Posts

Tags

News

  • Inappropriate comments will be deleted at my discretion.

    The information and code samples in this weblog is provided "AS IS" without warranty of any kind, either expressed or implied, including but not limited to the merchantability and/or fitness for a particular purpose.

Community

Email Notifications

Tool suppliers

Tools

General

Microsoft

Favorite blogs

Archives

Centralizing AssemblyInfo settings, or simplify versioning of solutions

I'm working on a solution in Visual Studio 2003 at the moment, which contains about 15 assemblies. All these assemblies have a AssemblyInfo.cs file which contains more or less the same information. In general, when you look at larger solutions, you will have only a few settings that might differ between these assemblies. A standard AssemblyInfo.cs file will look like this:

using System.Reflection;
using System.Runtime.CompilerServices;
 
[assembly: AssemblyTitle("")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]        
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyDelaySign(false)]
[assembly: AssemblyKeyFile("")]
[assembly: AssemblyKeyName("")]

I found that when you look at what the difference between all these AssemblyInfo.cs files are, you are generally left with the following options:

[assembly: AssemblyTitle("The title for your assembly")]
[assembly: AssemblyDescription("A description for your assembly")]

So that all seams bit of a waste. It would make life a lot easier if you have all the stuff that is identical for all assemblies in your solution in one place. It is really simple to accomplish this, and I'm still surprised that not that many people do this. So I will try to explain how to do it here.

Step 1 - Create a SolutionInfo.cs

The SolutionInfo.cs file contains all the settings that are identical for all assemblies in the solution. The easiest way to do this is by copying an existing AssemblyInfo.Cs file to the root directory of your solution and renaming it to SolutionInfo.cs. You then remove all the stuff you don't need until you're left with something that looks like the above. You then add the SolutionInfo.cs to the solution. Right-click on the solution in the Solution Explorer and select Add existing item. Then select the file SolutionInfo.cs and click OK. 

In my case, the SolutionInfo.Cs file looks like this:

using System;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Security;
using System.Runtime.CompilerServices;
 
[assembly: AssemblyCompany("My Company Name")]
[assembly: AssemblyProduct("My wonderful product")]
[assembly: AssemblyCopyright("(c) 2004-2007 Yours truly")]
[assembly: AssemblyTrademark("(R) Jan Schreuder")]
 
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyDelaySign(false)]
 
[assembly: CLSCompliant(true)]
[assembly: ComVisible(false)]

Step 2 - Create a SolutionVersionInfo.cs

The SolutionVersionInfo.cs file contains only the setting that add's the version information to the assembly. By keeping this value in one location you make it very simple to change the version number of all assemblies in your solution. The steps to create such a file is similar to creating the SolutionInfo.cs file. Just make a copy and remove all the stuff you don't need and follow the steps to add the file to the solution as described earlier.

My SolutionVersionInfo.cs looks like this:

[assembly: System.Reflection.AssemblyVersion("2.1.4.*")]

Step 3 - Remove items from all AssemblyInfo.cs files

Now that you have most information in two Solution*.cs files, you can strip all information that is in those files from the AssemblyInfo.cs files that are still in the individual assemblies. I'm not going to explain that, we all know how to remove lines of code, right? smile_tongue

The AssemblyInfo.cs file in my assemblies look like this:

using System;
using System.Reflection;
 
[assembly: AssemblyTitle("My Assembly Title")]
[assembly: AssemblyDescription("My Wonderful Assembly that does excellent stuff.")]

Step 4 - Link the SolutionInfo.cs and SolutionVersionInfo.cs to the assemblies

All we need to do now is make sure all assemblies use the SolutionInfo.cs and SolutionVersionInfo.cs files. That can be done by following these ? steps:

  1. Right-Click on the assembly in the Solution Explorer.
  2. Select Add / Add Existing item
  3. Browse to the SolutionInfo.cs file.
  4. Select the file but make sure to click on the arrow-down image in the Open button.
  5. From the menu that appears, select Link File.

And that's it. Most of the stuff that is normally scattered around a solution is now in one place and changing the version number of your assemblies can be done in one location.

Comments

Ramon Smits said:

Good tip Jan! We also use this here at our projects. We call it a "GlobalAssemblyInfo" because we share it accross multipe solutions. We also extended it with some #if..#else..#endif's to add some more extensions. For example.. we keep te assembly info the same while working on the same branch and increase the fileversion. This depends on the type of build. We also add if the build is a Release, Developer, Continious Integration or Patch build.
# November 3, 2006 7:38 AM

Johan; thinking out loud. » Managing several AssemblyInfo files in Visual Studio said:

PingBack from http://idstam.com/en/index.php/2007/05/02/managing-several-assemblyinfo-files-in-visual-studio/
# May 2, 2007 5:42 AM

KooKiz said:

Maybe I missed something, but I don't find the "Add link" button on Visual Studio 2003, only on the 2005 version :/

How did you add a link with VS2003 ?

# January 2, 2008 4:42 PM

Jan Schreuder said:

Yes, you missed something. On the open button in VS 2003 you will see an arrow down on the right-hand side. Click that, and you should be able to select link.

# January 3, 2008 8:53 PM

KooKiz said:

I know what's the problem : this trick doesn't work with an ASP.NET project. Damn, it would have been so useful :/

# January 4, 2008 11:15 AM

Johan; thinking out loud. » Managing several AssemblyInfo files in Visual Studio said:

Pingback from  Johan; thinking out loud. » Managing several AssemblyInfo files in Visual Studio

# April 15, 2008 9:37 AM

Common Assembly Attributes « Coding for Fun and Profit said:

Pingback from  Common Assembly Attributes « Coding for Fun and Profit

# November 26, 2008 4:25 AM

Nelson said:

Me sirvió de mucho, Gracias

# December 2, 2009 4:11 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 6 and 7 and type the answer here: