65.9K
CodeProject is changing. Read more.
Home

.NET Core Versioning Demystified

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.85/5 (13 votes)

Feb 24, 2018

CPOL

2 min read

viewsIcon

28322

Version all your .NET Core projects in one swoop fell!

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>
    <!-- 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