Just create a file e.g. GlobalAssemblyInfo.cs in the solution root folder then add the necessary attributes to it and finally add it as an existing item to each project as a link.
In Solution Explorer right click on the project name > Add > Existing item... and in the dialog box select Add As Link option from the dropdown list as you can see on this image.
// Content of GlobalAssemblyInfo.cs file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Please note:
- you have to remove these attributes from each project's
Properties\AssemblyInfo.cs file.
- you can also move other assembly attributes into the
GlobalAssemblyInfo.cs file as well
The result is that you will have only one file where you can set the version and it will apply to all projects.
UPDATE #1:
In .NET 5 projects an AssemblyInfo.cs file is automatically generated during build, by default.
It seems that only 7 attributes is generated automatically:
AssemblyCompanyAttribute
AssemblyProductAttribute
AssemblyConfigurationAttribute
AssemblyVersionAttribute
AssemblyFileVersionAttribute
AssemblyInformationalVersionAttribute
AssemblyTitleAttribute
You have two options here:
- Disable automatic generation of
AssemblyInfo.cs file.
- Leave automatic generation of
AssemblyInfo.cs file enabled and turn off generation of specific attributes.
Create a file (name: Directory.Build.props) and put it next to the .sln file so that it will be applied to all the projects within the solution.
Example #1 - Disable automatic build of AssemblyInfo.cs file
Directory.Build.props:
<Project>
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>
Example #2 - Disable only specific attribute generation
In this case simply add <Generate...>false</Generate...> line to disable a specific attribute where ... is the attribute type name.
Directory.Build.props:
<Project>
<PropertyGroup>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
</PropertyGroup>
</Project>
Remarks
Learn more about AssemblyInfo properties in SDK-style project files.
This update applies to .NET Core versions as well.
If a specific project has special needs you can override these settings in the .csproj file as well.
As for me I usually put the attributes as follows:
GlobalAssemblyInfo.cs
AssemblyCompanyAttribute
AssemblyProductAttribute
AssemblyCopyrightAttribute
AssemblyConfigurationAttribute
AssemblyTrademarkAttribute
AssemblyCultureAttribute
AssemblyVersionAttribute
AssemblyFileVersionAttribute
AssemblyInformationalVersionAttribute
ComVisibleAttribute
AssemblyInfo.cs (in specific projects)
AssemblyTitleAttribute
AssemblyDescriptionAttribute
GuidAttribute