Giter VIP home page Giter VIP logo

ngitversion's Introduction

Current Status:

Build status

NGitVersion

Auto-increment your DLL versions based on git history.

Out-of-the-box NGitVersion populates your DLLs with the following versions:

screenshot

  • File Version: 1.0.0.34, where 34 is the Git auto-incremented version
  • Product Version: 1.0.0.34, Hash b716d1b, BuildConfig DEBUG, HasLocalChange True, where:
    • Hash is the git "short hash" of the current commit
    • BuildConfig is the build configuration (DEBUG / RELEASE)
    • HasLocalChange tells whether some file has been locally edited

NGitVersion introduces a C# project called NGitVersion that generates on build two files GLobalAssemblyInfo.cs and GLobalAssemblyInfo.cpp. Just reference the NGitVersion project and GlobalAssemblyInfo.* files in your existing projects in order to get it work with your own DLLs.

NGitVersion is only a few lines of code. It is based on the template engine StringTemplate and the git-client LibGit2Sharp.

You can easily:

  • Edit the templates, that generate the GLobalAssemblyInfo.* files
  • Edit the underlying model Model.cs to change the major and minor version, product name...
  • Extend the underlying model
    • to get more information from your Git repository (i.e. current branch, last commit description)
    • to get additional information from your build environment, like OS version/architecture, tool version, date...
  • Add more templates
    • i.e. to generate a file containing the commit-history, the patch of the local changes

Usage

1) Get NGitVersion

Clone NGitVersion repository and copy its /src/NGitVersion/ subfolder to your target solution folder.

Alternatively, if you are confident with git subtree:

git subtree add --prefix my/target/folder https://github.com/jeromerg/NGitVersion master --squash

(update command)

git subtree pull --prefix my/target/folder https://github.com/jeromerg/NGitVersion master --squash

2) Add NGitVersion project to your Visual Studio solution

Add the /src/NGitVersion/NGitVersion.csproj to your solution.

3) Build

Typical issue: Antlr4.StringTemplate and LibGit2Sharp are not found: Fix the path to NuGet packages folder in the NGitVersion.csproj file:

  • Either search and fix ..\packages\ string within in the project file
  • Or remove/re-install nuget-dependencies Antlr4.StringTemplate and LibGit2Sharp

Linux/mono issue: install 0.23-pre version of LibGit2Sharp with 'mono ~/bin/nuget/nuget.exe install LibGit2Sharp -Pre' to avoid dll not found errors.

The build generates files into the src\NGitVersion\Generated\ folder. Check that they exist and are properly generated from the templates located in src\NGitVersion\Templates\.

Upgrade your projects

Now you can upgrade your projects to support Git automatic DLL versioning.

C# Project

  1. Add NGitVersion project as project reference

  2. Add manually the ReferenceOutputAssembly element to your CSharp.csproj (optional):

     <ProjectReference Include="..\..\NGitVersion\NGitVersion.csproj">
         <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
         <Project>{badb59fb-1a14-42af-b314-152c4787f437}</Project>
         <Name>NGitVersion</Name>
      </ProjectReference>
    

From MSDN: If true, the assembly is used on the compiler command line during the build. ... We just reference the NGitVersion project to ensure the correct build-order, so we disable this functionality.

  1. Add file src\NGitVersion\Generated\GlobalAssemblyInfo.cs as a link (Add by using the Add as link button in Add Existing Item dialog)
  2. Remove conflicting entries from the existing project AssemblyInfo.cs.
  3. Build: Check that the built DLL contains the metadata defined in the generated GlobalAssemblyInfo.cs file.

Native and C++ CLI Project

  1. Add NGitVersion project as project reference

    • Uncheck "Properties>Reference Assembly Output" in Add Reference dialog
  2. Copy and include following files into your project (eventually merge with existing):

    • For C++ and C++ CLI: NGitVersion\Resource\version.rc2 as Resource Compiler
    • For C++ CLI: NGitVersion\Resource\Assembly.cpp as C/C++ Compiler
  3. Fix all TODOs in both files, in particular the relative path to the generated src\NGitVersion\Generated\GlobalAssemblyInfo.h file.

  4. Build: Check that the built DLL contains the metadata defined in the generated GlobalAssemblyInfo.h file.

Customize

ngitversion's People

Contributors

jeromerg avatar sonologic avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.