If you have many C# projects, you may want all your assemblies to have the same version numbers. Remember that the version numbers are defined in the ‘AssemblyInfo.cs’ file in each project.
There are several mechanisms to achieve this:
- Programmatically change all the ‘AssemblyInfo.cs’-files to update the version number.
You could write a tool that updates the version number of all your projects. This tool could then be integrated in your build process. This is cumbersome and often not so simple if your projects are checked in a source control system.
- Define the version-numbers in a single file that is used by all your projects. This technique is explained in this article.
- Define the version-numbers in a separate assembly that is referenced by all projects.
In this post I will elaborate on the third mechanism (because I’ve never seen this explained anywhere else).
Create a new C# project (called Metadata.csproj) that contains all the metadata that is shared across your projects. This project is very simple and contains only 1 class:
Now you can reference this assembly from all your other C# projects, and you can use the data from the ‘AssemblyInfo.cs’ files like this:
Note that the ‘Metadata.dll’ assembly is used by the compiler to fill in the correct metadata. However this assembly is not needed at runtime! So you don’t need to deploy this assembly to your users, it is only needed by the compiler.