Applications and libraries contain information about themself like the manufacturer, productname, version, etc. We can see them, if we right-click them and view the properties:
They are defined in the AssemblyInfo-file, which you can find under properties in your Visual Studio project. When we have many projects in a solution, managing all these AssemblyInfo can become cumbersome, if we need to change values like i.e. the version. Sure, we could use find and replace, but it does not really feel like a professional solution, does it?
The initial situation
We have VS-solution, with a console-application and a library.
Solving the requirement
The solution is to create a common AssemblyInfo, which contains only the information, that all projects have in common. In our example, the AssemblyVersion- and AssemblyFileVersion. Choosing the shared information might be different in your project.
- In MyApplication create a new file SharedAssemblyInfo.cs
- Clear the content of the file completely
- Move it into the Properties-folder
Your project should now look like this:
- Insert the following "using" into the SharedAssemblyInfo.cs
- Cut the following part from AssemblyInfo.cs and paste it into the SharedAssemblyInfo.cs
// Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("18.104.22.168")] [assembly: AssemblyFileVersion("22.214.171.124")]
Link the SharedAssemblyInfo from other projects
Visual Studio allows us to link file. Thats what we’ll do now to have a common SharedAssemblyInfo.
- Open the AssemblyInfo.cs of the MyLibrary-project and remove the AssemblyVersion and AssemblyFileVersion.
- Right-Click on the MyLibrary-project -> Add Existing Item
- Select the SharedAssemblyInfo.cs you’ve created in step 1
- Select the little arrow and click on Add As Link:
- Move the SharedAssemblyInfo into the Properties folder.
We’re done! Your project should now look like this:
Now whenever you have a new project, simply follow the steps 6-10!