If you have a multi-layered application you may want to keep the file and assembly version numbers of all the assemblies the same. This would entail editing each AssemblyInfo.cs file. An alternative is to create a single file holding the versions and referencing it from each projects. Let me show you how.
Imagine the following solution.
If we look in the Release folder we see:
The Product Version shown above relates to the AssemblyFileVersion attribute in <project> -> Properties -> AssemblyInfo.cs file and is an OS file version that is not .NET specific. The AssemblyVersion is .NET specific and is the version used by the .NET loader.
If we needed to increment the version we would have to edit five AssemblyInfo.cs files. Let me show you how we can have a single file. For the sake of this tutorial, I will keep both versions the same.
Creating a SolutionInfo.cs File
The first step is to copy an existing AssemblyInfo.cs file into the solution folder and rename it to SolutionInfo.cs.
Edit this file and remove everything except the two version attributes. Below I have changed the versions to 184.108.40.206.
For each project you need to do the following:
- Edit the projects AssemblyInfo.cs file and remove the two version attributes but leave everything else.
Right click the VS project and select Add -> Existing Project. Now here is the important bit.
Select the SolutionInfo.cs file however; Click on the arrow next to the Add button and select Add As Link.
Notice the file has been added to your project with an icon that has an arrow indicating a link.
Now let’s rebuild the solution and check the Release folder.
They now all have the same version 220.127.116.11. Now you only need to edit the version once in SolutionInfo.cs for all projects.