Thursday, February 20, 2020

GitInfo. How using versioning from Git Tag and C# projects (frameworks and core)

In all big or small companies, you might be using versioning, I recommend using GitInfo, because it is a simple project that will help you be more advance.

A huge plus of GitInfo project is that besides the library itself you don’t need anything else


For dotnet core projects, I enable support Git and make the first commit and after I add Git Tag "0.1.0".

Then I add NuGet package "GitInfo"

Next step you need to add AssemblyInfo.cs, better to Properties folder

using System.Reflection;

[assembly: AssemblyVersion (ThisAssembly.Git.BaseVersion.Major + "." + ThisAssembly.Git.BaseVersion.Minor + "." + ThisAssembly.Git.BaseVersion.Patch)]

[assembly: AssemblyFileVersion (ThisAssembly.Git.SemVer.Major + "." + ThisAssembly.Git.SemVer.Minor + "." + ThisAssembly.Git.SemVer.Patch)]

[assembly: AssemblyInformationalVersion (
    ThisAssembly.Git.SemVer.Major + "." + 
    ThisAssembly.Git.SemVer.Minor + "." + 
    ThisAssembly.Git.Commits + "-" + 
    ThisAssembly.Git.Branch + "+" + 
    ThisAssembly.Git.Commit)]




And last step change csproj, you need add 3 rows

<PropertyGroup>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    </PropertyGroup>

After that, you can use GitInfo and versioning anywhere

Good luck!!!