Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / DevOps

.NET Core Versioning Demystified

4.85/5 (14 votes)
19 Mar 2020CPOL2 min read 28.3K  
Version all your .NET Core projects in one swoop fell!
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:

XML
<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:

XML
<Project>
  <PropertyGroup>
    <VersionPrefix>1.2.3</VersionPrefix>
    <VersionSuffix>abc</VersionSuffix>
    <!-- etc.... -->
  </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

  • 19th March, 2020: V 1.0

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)