If you want a command line version installed on your machine then you can use Chocolatey to install GitVersion
Available on Chocolatey under GitVersion.Portable
choco install GitVersion.Portable
Switches are available with GitVersion /?
By default GitVersion returns a json object to stdout containing all the variables which GitVersion generates. This works great if you want to get your build scripts to parse the json object then use the variables, but there is a simpler way.
GitVersion.exe /output buildserver
will change the mode of GitVersion to write out the variables to whatever build server it is running in. You can then use those variables in your build scripts or run different tools to create versioned NuGet packages or whatever you would like to do. See build servers for more information about this.
GitVersion.exe /updateassemblyinfo
will recursively search for all AssemblyInfo.cs
or AssemblyInfo.vb
files in the git repo and update them.
It will update the following assembly attributes:
AssemblyVersion
will be set to theAssemblySemVer
variable.AssemblyFileVersion
will be set to theMajorMinorPatch
variable with a appended.0
.AssemblyInformationalVersion
will be set to theInformationalVersion
variable.
Note that contrary to when using the MSBuild Task the attributes must already exist in the AssemblyInfo.cs
or AssemblyInfo.vb
files prior to calling GitVersion.
By adding /updateassemblyinfo <filenames>
the name of AssemblyInfo file to update can be set. This switch can accept multiple files with the path to the file specified relative to the working directory.
GitVersion can generate an assembly info source file for you if it does not already exist. Use the /ensureassemblyinfo
switch alongside /updateassemblyinfo <filename>
, if the filename specified does not exist it will be generated based on a known template that adds:
AssemblyVersion
will be set to theAssemblySemVer
variable.AssemblyFileVersion
will be set to theMajorMinorPatch
variable with a appended.0
.AssemblyInformationalVersion
will be set to theInformationalVersion
variable.
This can be done for *.cs, *.vb and *.fs files.
When requesting that GitVersion generate an assembly info file you are limited to only specifying a single <filename>
within the /updateassemblyinfo
switch, this is to prevent the creation of mulitple assembly info files with the same assembly version attributes. If this occurs your build will fail.
GitVersion.exe /updateassemblyinfo AssemblyInfo.cs /ensureassemblyinfo
A file is generated that contains version attributes (AssemblyVersion
, AssemblyFileVersion
, AssemblyInformationalVersion
)
GitVersion.exe /updateassemblyinfo AssemblyInfo.cs /ensureassemblyinfo
All known attributes (AssemblyVersion
, AssemblyFileVersion
, AssemblyInformationalVersion
) will be updated
GitVersion.exe /updateassemblyinfo AssemblyInfo.cs AssemblyVersionInfo.cs /ensureassemblyinfo
Will result in command line argument error
GitVersion.exe /updateassemblyinfo AssemblyInfo.cs AssemblyVersionInfo.cs
Will iterate through each file and update known attributes (AssemblyVersion
, AssemblyFileVersion
, AssemblyInformationalVersion
).
/overrideconfig [key=value]
will override appropriate key from 'GitVersion.yml'.
At the moment only tag-prefix
option is supported. Read more about Configuration.
It will not change config file 'GitVersion.yml'.
GitVersion.exe /output json /overrideconfig tag-prefix=custom
To use on mac or linux, install mono-complete
then just run mono GitVersion.exe