Ever had a solution with loads of projects? You must be familiar with the fact that we always forget to update the
file for each project. A lot of data in that
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.
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:
[assembly: AssemblyProduct("This is my new funky product!")]
[assembly: AssemblyCopyright("Copyright © MyCompany 2011")]
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:
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
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
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:
[assembly: AssemblyDescription("This is my funky description")]
Now compile your project and you'll see it works! (at least the assembly information compiles, the rest is up to you
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.