In this tip, you will learn an easy way to provide a common version number and version information for your .NET Core 2.0 projects.
Background
We have a VS2017 solution containing hundreds of projects, mostly in C#.
The build process is automated using mostly free tools:
- Gitea GIT server
- Continuous integration builder running TeamCity
The C# projects are versioned using the 'VersionInfo.cs' trick, which means that there is one central version file that is added as a link in all projects in the Visual Studio solution explorer.
This trick is described here.
We use a custom 'AutoBuildVersion
' tool that modifies the contents of the 'VersionInfo.cs' file (and also other files like Visual C .rc files).
Sadly, I cannot disclose the source code of this tool, but there is a good alternative mentioned at the bottom of this tip.
So far, so good, until recently .NET Core and .NET Standard projects started popping up that have a totally different way of storing version information.
Instead of using traditional AssemblyInfo.cs files, for .NET Core 2.0 projects, the version information in now stored in the .csproj files.
Using the Code
After hunting the internet for days, I finally stumbled on this tip, a Directory.Build.props file that will version all .NET Core directories beneath it, example:
<Project>
<PropertyGroup>
<Authors>Zeeland BV</Authors>
<Company>Zeeland BV</Company>
<Copyright>Zeeland BV</Copyright>
<AssemblyVersion>10.0.30000.0</AssemblyVersion>
<FileVersion>10.0.30000.0</FileVersion>
<Version>10.0.30000</Version>
</PropertyGroup>
</Project>
I also posted my issue on the dotnet/coreclr GitHub site and got this interesting answer about a Common.props file:
<Project>
<PropertyGroup>
<VersionPrefix>1.2.3</VersionPrefix>
<VersionSuffix>abc</VersionSuffix>
</PropertyGroup>
</Project>
Then in your .csproj, add <Import Project="..\..\Common.props" />
right after the <project>
element opener.
But I think I will stick with the first solution of a Directory.Build.props file as this seems to be the easiest option for me.
Points of Interest
Other interesting tools:
History