Despite this core principal one of the most common areas of repetition is in the AssemblyInfo.cs file found in every single C# project, this file contains largely boilerplate content and could easily be shared across the solution by means of a Shared AssemblyInfo.
Before we delve in to the technical solution to this problem let’s quickly visit the attributes contained within AssemblyInfo.cs:
Of the above only AssemblyTitle, AssemblyDescription and Guid need to be tied specifically to the assembly all of the remaining attributes can be moved to a shared AssemblyInfo.
The first step in avoiding repetition in your AssemblyInfo.cs is to create the shared file, simply duplicate one of your existing AssemblyInfo.cs file as SharedAssemblyInfo.cs into the root directory of your repository. It is best to surface this file in your solution by creating a solution folder called “Solution Items” in your solution and adding the SharedAssemblyInfo.cs to this folder, this will enable all of the Visual Studio Source Control functionality in addition to providing quick access to this key file.
If you have more than a handful of projects in your solution the next step has the potential to waste a considerable amount of time. There are two discrete tasks that you need to undertake to complete the conversion to a Shared AssemblyInfo:
All of this can be automated, including the creation of a SharedAssemblyInfo.cs with this PowerShell script. I have also put a sample project up on GitHub to use as a playground to identify other use cases that are not covered by the script, feel free to fork, change and submit a pull request.
This script is idempotent and as such can be executed as many times over the solution as required, changes will only be made once and as such you can execute this script repeatedly as projects are added to the solution, bringing them into line as and when needed.