Click here to Skip to main content
15,357,464 members
Articles / DevOps
Tip/Trick
Posted 24 Feb 2018

Stats

21.6K views
20 bookmarked

.NET Core Versioning Demystified

Rate me:
Please Sign up or sign in to vote.
4.85/5 (14 votes)
19 Mar 2020CPOL2 min read
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)

Share

About the Author

RickZeeland
Software Developer
Netherlands Netherlands
Software developer in the Netherlands, currently working on Video Surveillance applications.
Experience: C#, C++, VB, ASP, SQL Server, PostgreSQL, Gitea, TeamCity.
It all started with Black&White, no not the whiskey but the Sinclair ZX81 followed by several Atari's and PC's. The journey continues ...

Comments and Discussions

 
QuestionCode snippet for changing AssemblyVersion and AssemblyFileVersion Pin
Qwertie23-Apr-20 16:41
MemberQwertie23-Apr-20 16:41 
QuestionCode snippet for changing AssemblyVersion and AssemblyFileVersion Pin
Qwertie23-Apr-20 16:41
MemberQwertie23-Apr-20 16:41 
PraiseRe: Code snippet for changing AssemblyVersion and AssemblyFileVersion Pin
RickZeeland23-Apr-20 19:36
mveRickZeeland23-Apr-20 19:36 
GeneralMy vote of 5 Pin
raddevus21-Apr-18 8:34
mvaraddevus21-Apr-18 8:34 
Interesting idea. Thanks for sharing.
GeneralMy vote of 5 Pin
L Hills26-Feb-18 3:16
MemberL Hills26-Feb-18 3:16 
GeneralRe: My vote of 5 Pin
RickZeeland26-Feb-18 5:39
mveRickZeeland26-Feb-18 5:39 
SuggestionA questions and a proposition... Pin
Kornfeld Eliyahu Peter25-Feb-18 20:36
professionalKornfeld Eliyahu Peter25-Feb-18 20:36 
GeneralRe: A questions and a proposition... Pin
RickZeeland25-Feb-18 22:31
mveRickZeeland25-Feb-18 22:31 
GeneralRe: A questions and a proposition... Pin
Kirk Wood21-Mar-20 3:55
MemberKirk Wood21-Mar-20 3:55 
GeneralRe: A questions and a proposition... Pin
RickZeeland21-Mar-20 4:25
mveRickZeeland21-Mar-20 4:25 
GeneralRe: A questions and a proposition... Pin
johannesnestler19-Mar-20 23:57
Memberjohannesnestler19-Mar-20 23:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.