Current Status:
Auto-increment your DLL versions based on git history.
Out-of-the-box NGitVersion populates your DLLs with the following versions:
- File Version:
1.0.0.34
, where34
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 commitBuildConfig
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
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
Add the /src/NGitVersion/NGitVersion.csproj
to your solution.
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
andLibGit2Sharp
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\
.
Now you can upgrade your projects to support Git automatic DLL versioning.
-
Add NGitVersion project as project reference
-
Add manually the
ReferenceOutputAssembly
element to yourCSharp.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.
- Add file
src\NGitVersion\Generated\GlobalAssemblyInfo.cs
as a link (Add by using the Add as link button in Add Existing Item dialog) - Remove conflicting entries from the existing project
AssemblyInfo.cs
. - Build: Check that the built DLL contains the metadata defined in the generated
GlobalAssemblyInfo.cs
file.
-
Add NGitVersion project as project reference
- Uncheck "Properties>Reference Assembly Output" in Add Reference dialog
-
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
- For C++ and C++ CLI:
-
Fix all TODOs in both files, in particular the relative path to the generated
src\NGitVersion\Generated\GlobalAssemblyInfo.h
file. -
Build: Check that the built DLL contains the metadata defined in the generated
GlobalAssemblyInfo.h
file.
- Customize model file /src/NGitVersion/Model/Model.cs (major, minor, build versions, company name...)
- Edit/Add templates in /src/NGitVersion/Templates/