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:
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:
[assembly: AssemblyCompany("My Company Name")]
[assembly: AssemblyProduct("My wonderful product")]
[assembly: AssemblyCopyright("(c) 2004-2007 Yours truly")]
[assembly: AssemblyTrademark("(R) Jan Schreuder")]
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:
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?
The AssemblyInfo.cs file in my assemblies look like this:
[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:
- Right-Click on the assembly in the Solution Explorer.
- Select Add / Add Existing item
- Browse to the SolutionInfo.cs file.
- Select the file but make sure to click on the arrow-down image in the Open button.
- 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.