Shared AssemblyInfo in VS projects

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:

SharedAssemblyInfo_AssemblyProperties

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.

SharedAssemblyInfo_VSSolution

For these, the goal is to have a common version, which we can edit in the shared AssemblyInfo.

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.

  1. In MyApplication create a new file SharedAssemblyInfo.cs
  2. Clear the content of the file completely
  3. Move it into the Properties-folder

Your project should now look like this:

SharedAssemblyInfo_SharedAssemblyInfo_File

  1. Insert the following "using" into the SharedAssemblyInfo.cs
    using System.Reflection;
    
  2. 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("1.0.0.0")]
    [assembly: AssemblyFileVersion("1.0.0.0")]
    

Link the SharedAssemblyInfo from other projects
Visual Studio allows us to link file. Thats what we’ll do now to have a common SharedAssemblyInfo.

  1. Open the AssemblyInfo.cs of the MyLibrary-project and remove the AssemblyVersion and AssemblyFileVersion.
  2. Right-Click on the MyLibrary-project -> Add Existing Item
  3. Select the SharedAssemblyInfo.cs you’ve created in step 1
  4. Select the little arrow and click on Add As Link:

    SharedAssemblyInfo_AddSharedAssemblyInfoAsLink

  5. Move the SharedAssemblyInfo into the Properties folder.

We’re done! Your project should now look like this:

SharedAssemblyInfo_Completed

Now whenever you have a new project, simply follow the steps 6-10!