Click here to Skip to main content
Click here to Skip to main content

Solution information, prevent duplicate information in your projects

, 16 May 2011
Rate this:
Please Sign up or sign in to vote.
Solution information file
Ever had a solution with loads of projects? You must be familiar with the fact that we always forget to update the AssemblyInfo file for each project. A lot of data in that AssemblyInfo is copied to other projects and maintaining them (updating version numbers for example) is forgotten most of the time. Do you recognize yourself? Well, here's a tip / trick that makes you have a good weekend. Wink | ;)
 
If we could create an AssemblyInformation file that would be shared, we don't have to think about updating all projects. We could just update one single file and recompile, all projects are updated accordingly. Here's the good news, we can!
Right click your solution in the Solution Explorer and choose [ Add > New Item ].
 
New in the new created class, we'll enter all shared assembly information, for example:
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("MyCompany")]
[assembly: AssemblyProduct("This is my new funky product!")]
[assembly: AssemblyCopyright("Copyright © MyCompany 2011")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
Now we repeat this step, add a new item to the solution, and name it SolutionVersion.cs. We add solution version information in this file:
using System.Reflection;
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
 
So far so good, we now need to add the files to our existing projects. Right click a project and choose [ Add > Existing Item ]. In the dialog box that appears, browse to the folder where SolutionInfo.cs and SolutionVersion.cs are stored, and select them both. Now the trick is to click on the little arrow next to the 'Add' button, and choose 'Add as Link'.
 
Don't worry that your project doesn't compile anymore. The AssemblyInformation is now duplicated, and the C# compiler does not like that. You need to remove the duplicates from the AssemblyInfo.cs file so it looks like this:
using System.Reflection;
using System.Runtime.InteropServices;
 
[assembly: AssemblyTitle("WinFormsTestProject")]
[assembly: AssemblyDescription("This is my funky description")]
 
[assembly: Guid("223d5eba-d959-4337-bd8f-cc64163c0daf")]
Now compile your project and you'll see it works! (at least the assembly information compiles, the rest is up to you Smile | :)
You can repeat this step (adding links to the solution files) for each project in your solution. If you update the SolutionInfo file and recompile your projects, you'll see that the information is adopted in your assemblies.
 
I love it when a plan comes together. Wink | ;)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Eduard Keilholz
Software Developer (Senior) http://www.today-it.nl
Netherlands Netherlands
In 1998 I started as webdesigner programming websites in Perl and later PHP. After two years wrote most of the websites in ASP and from then on lost the feeling with a linux/unix platform.
 
Since 2001 interested in Windows applications and now writing software using mostly C# for about 7 years now.
Follow on   Twitter

Comments and Discussions

 
GeneralWorks ok for File Version and Product Version, by the Assemb... PinmemberPaulandr18-May-11 14:57 
GeneralCool, I like it (and I tested it). PinmemberFDW18-May-11 0:45 
GeneralMy vote of 5. excellent tip PinmemberRhuros12-May-11 2:21 
GeneralReason for my vote of 5 Simple, pratical solution (no pun in... PinprotectorAspDotNetDev25-Mar-11 10:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 16 May 2011
Article Copyright 2011 by Eduard Keilholz
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid