Skip to content

Commit 7e6b1b3

Browse files
committed
Merge pull request #536 from GitTools/updateTask
Update task
2 parents f8ffe96 + e085c34 commit 7e6b1b3

14 files changed

+136
-274
lines changed

BREAKING CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ v3.0.0
33
- `AssemblyFileSemVer` variable removed, AssemblyVersioningScheme configuration value makes this variable obsolete
44
- Variables `ClassicVersion` and `ClassicVersionWithTag` removed
55
- MSBuild task arguments (AssemblyVersioningScheme, DevelopBranchTag, ReleaseBranchTag, TagPrefix, NextVersion) have been removed, use GitVersionConfig.yaml instead
6-
- GitVersionTask ReleaseDateAttribute no longer has OriginalReleaseDate
6+
- GitVersionTask ReleaseDateAttribute no longer exists

docs/more-info/variables.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ For the `release/3.0.0` branch of GitVersion it shows:
2424
"NuGetVersion":"3.0.0-beta0001"
2525
}
2626
```
27+
28+
29+
#### Why is AssemblyVersion only set to Major.Minor?
30+
31+
This is a common approach that gives you the ability to roll out hot fixes to your assembly without breaking existing applications that may be referencing it. You are still able to get the full version number if you need to by looking at its file version number.
32+

docs/usage.md

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Usage
2+
23
There are two main ways to consume GitVersion, the first is by running GitVersion.exe. The second is an MSBuild task. The MSBuild task is really easy to get up and running, simply install GitVersionTask from NuGet and it will integrate into your project and write out variables to your build server if it's running on one. The exe offers more options and works for not just .net projects.
34

45
- [A Command Line tool](#command-line)
56
- [An MSBuild Task](#msbuild-task)
67
- [A NuGet Library package](#nuget-library)
78
- [A Ruby Gem](#gem)
89

10+
911
## Command Line
12+
1013
If you want a command line version installed on your machine then you can use [Chocolatey](http://chocolatey.org) to install GitVersion
1114

1215
Available on [Chocolatey](http://chocolatey.org) under [GitVersion.Portable](http://chocolatey.org/packages/GitVersion.Portable)
@@ -15,57 +18,128 @@ Available on [Chocolatey](http://chocolatey.org) under [GitVersion.Portable](htt
1518
1619
Switches are available with `GitVersion /?`
1720

21+
1822
### Output
23+
1924
By default GitVersion returns a json object to stdout containing all the [variables](more-info/variables.md) 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.
2025

2126
`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](build-server-support.md) for more information about this.
2227

2328

2429
## MSBuild Task
25-
The MSBuild task will wire GitVersion into the MSBuild pipeline of a project and automatically stamp that assembly with the appropriate SemVer information
2630

2731
Available on [Nuget](https://www.nuget.org) under [GitVersionTask](https://www.nuget.org/packages/GitVersionTask/)
2832

2933
Install-Package GitVersionTask
3034

31-
Remove the `Assembly*Version` attributes from your `Properties\AssemblyInfo.cs` file. Sample default:
35+
The MSBuild task will wire GitVersion into the MSBuild pipeline of a project and perform several actions.
36+
37+
### 1. Inject version metadata into the assembly
38+
39+
Task Name: `GitVersionTask.UpdateAssemblyInfo`
40+
41+
#### AssemblyInfo Attributes
42+
43+
At build time a temporary AssemblyInfo.cs will be created that contains the appropriate SemVer information. This will will be included in the build pipeline.
44+
45+
Ensure you remove the `Assembly*Version` attributes from your `Properties\AssemblyInfo.cs` file so as to not get duplicate attribute warnings. Sample default:
3246

3347
[assembly: AssemblyVersion("1.0.0.0")]
3448
[assembly: AssemblyFileVersion("1.0.0.0")]
35-
[assembly: AssemblyInformationalVersion("1.0.0.0")]
49+
[assembly: AssemblyInformationalVersion("1.1.0+Branch.master.Sha.722aad3217bd49a6576b6f82f60884e612f9ba58")]
3650

37-
Make sure there is a tag somewhere on master named `v1.2.3` before `HEAD` (change the numbers as desired). Now when you build:
51+
Now when you build:
3852

39-
* AssemblyVersion will be set to 1.2.0.0 (i.e Major.Minor.0.0)
40-
* AssemblyFileVersion will be set to 1.2.3.0 (i.e Major.Minor.Patch)
41-
* AssemblyInformationalVersion will be set to `1.2.4+<commitcount>.Branch.<branchname>.Sha.<commithash>` where:
42-
* `<commitcount>` is the number of commits between the `v1.2.3` tag and `HEAD`.
43-
* `<branchname>` is the name of the branch you are on.
44-
* `<commithash>` is the commit hash of `HEAD`.
53+
* `AssemblyVersion` will be set to the `AssemblySemVer` variable.
54+
* `AssemblyFileVersion` will be set to the `MajorMinorPatch` variable with a appended `.0`.
55+
* `AssemblyInformationalVersion` will be set to the `InformationalVersion` variable.
4556

46-
Continue working as usual and when you release/deploy, tag the branch/release `v1.2.4`.
4757

48-
If you want to bump up the major or minor version, create a `GitVersionConfig.yaml` file in the root of your repo and inside of it on a single line enter `next-version: <version you want>`, for example `next-version: 3.0.0`
58+
#### Other injected Variables
4959

50-
### Why is AssemblyVersion only set to Major.Minor?
60+
All other [variables](more-info/variables.md) will be injected into a internal static class.
61+
62+
```
63+
namespace AssemblyName
64+
{
65+
[CompilerGenerated]
66+
internal static class GitVersionInformation
67+
{
68+
public static string Major = "1";
69+
public static string Minor = "1";
70+
public static string Patch = "0";
71+
...All other variables
72+
}
73+
}
74+
```
75+
76+
77+
#### Accessing injected Variables
78+
79+
**All variables**
80+
81+
```
82+
var assemblyName = assembly.GetName().Name;
83+
var gitVersionInformationType = assembly.GetType(assemblyName + ".GitVersionInformation");
84+
var fields = gitVersionInformationType.GetFields();
85+
86+
foreach (var field in fields)
87+
{
88+
Trace.WriteLine(string.Format("{0}: {1}", field.Name, field.GetValue(null)));
89+
}
90+
```
91+
92+
**Specific variable**
93+
94+
```
95+
var assemblyName = assembly.GetName().Name;
96+
var gitVersionInformationType = assembly.GetType(assemblyName + ".GitVersionInformation");
97+
var versionField = gitVersionInformationType.GetField("Major");
98+
Trace.WriteLine(versionField.GetValue(null));
99+
```
100+
101+
102+
### 2. Populate some MSBuild properties with version metadata
103+
104+
Task Name: `GitVersionTask.GetVersion`
105+
106+
At build time all the derived [variables](more-info/variables.md) will be written to MSBuild properties so the information can be used by other tooling in the build pipeline.
107+
108+
The class for `GitVersionTask.GetVersion` has a property for each variable. However at MSBuild time these properties a mapped to MSBuild properties that are prefixed with `GitVersion_`. This prevents conflicts with other properties in the pipeline.
109+
110+
#### Accessing variable in MSBuild
111+
112+
After `GitVersionTask.GetVersion` has executed the properties can be used in the standard way. For example:
113+
114+
<Message Text="GitVersion_InformationalVersion: $(GitVersion_InformationalVersion)"/>
115+
116+
117+
### 3. Communicate variables to current Build Server
118+
119+
Task Name: `GitVersionTask.WriteVersionInfoToBuildLog`
120+
121+
If, at build time, it is detected that the build is occurring inside a Build Server server then the [variables](more-info/variables.md) will be written to the build log in a format that the current Build Server can consume. See [Build Server Support](build-server-support.md).
51122

52-
This is a common approach that gives you the ability to roll out hot fixes to your assembly without breaking existing applications that may be referencing it. You are still able to get the full version number if you need to by looking at its file version number.
53123

54124
### My Git repository requires authentication. What do I do?
55125

56126
Set the environmental variables `GITVERSION_REMOTE_USERNAME` and `GITVERSION_REMOTE_PASSWORD` before the build is initiated.
57127

128+
58129
## NuGet Library
130+
59131
To use GitVersion from your own code.
60132

61133
**Warning, we are not semantically versioning this library and it should be considered unstable.**
62134

63135
It also is not currently documented. Please open an issue if you are consuming the library to let us know, and why you need to.
64136

137+
65138
## Gem
139+
66140
Just a gem wrapper around the command line to make it easier to consume from Rake.
67141

68-
**NOTE** This is currenly not being pushed.. Please get in touch if you are using this
142+
**NOTE** This is currently not being pushed.. Please get in touch if you are using this
69143

70144
If you want a Ruby gem version installed on your machine then you can use [Bundler](http://bundler.io/) or [Gem](http://rubygems.org/) to install the `gitversion` gem.
71145

src/GitVersionCore.Tests/GitVersionCore.Tests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626
<Prefer32Bit>false</Prefer32Bit>
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29-
<DebugType>pdbonly</DebugType>
30-
<Optimize>true</Optimize>
29+
<DebugType>full</DebugType>
30+
<Optimize>false</Optimize>
3131
<OutputPath>bin\Release\</OutputPath>
3232
<DefineConstants>TRACE</DefineConstants>
3333
<ErrorReport>prompt</ErrorReport>
3434
<WarningLevel>4</WarningLevel>
3535
<Prefer32Bit>false</Prefer32Bit>
36+
<DebugSymbols>true</DebugSymbols>
3637
</PropertyGroup>
3738
<ItemGroup>
3839
<Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">

src/GitVersionExe.Tests/GitVersionExe.Tests.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
<WarningLevel>4</WarningLevel>
2323
</PropertyGroup>
2424
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25-
<DebugType>pdbonly</DebugType>
26-
<Optimize>true</Optimize>
25+
<DebugType>full</DebugType>
26+
<Optimize>false</Optimize>
2727
<OutputPath>bin\Release\</OutputPath>
2828
<DefineConstants>TRACE</DefineConstants>
2929
<ErrorReport>prompt</ErrorReport>
3030
<WarningLevel>4</WarningLevel>
31+
<DebugSymbols>true</DebugSymbols>
3132
</PropertyGroup>
3233
<ItemGroup>
3334
<Reference Include="ApprovalTests, Version=3.0.0.0, Culture=neutral, PublicKeyToken=11bd7d124fc62e0f, processorArchitecture=MSIL">

src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,9 @@ using System.Reflection;
44
[assembly: AssemblyVersion("2.0.0.0")]
55
[assembly: AssemblyFileVersion("2.3.4.0")]
66
[assembly: AssemblyInformationalVersion("2.3.4-beta.5+6.Branch.master.Sha.commitSha")]
7-
[assembly: Fake.ReleaseDate("2014-03-06")]
8-
[assembly: Fake.GitVersionInformation()]
97

108
namespace Fake
119
{
12-
[System.Runtime.CompilerServices.CompilerGenerated]
13-
[AttributeUsage(AttributeTargets.Assembly)]
14-
sealed class ReleaseDateAttribute : System.Attribute
15-
{
16-
public string Date { get; private set; }
17-
18-
public ReleaseDateAttribute(string date)
19-
{
20-
Date = date;
21-
}
22-
}
2310

2411
[System.Runtime.CompilerServices.CompilerGenerated]
2512
static class GitVersionInformation
@@ -45,28 +32,4 @@ namespace Fake
4532
public static string CommitDate = "2014-03-06";
4633
}
4734

48-
[System.Runtime.CompilerServices.CompilerGenerated]
49-
[AttributeUsage(AttributeTargets.Assembly)]
50-
sealed class GitVersionInformationAttribute : System.Attribute
51-
{
52-
public string Major { get { return "2"; } }
53-
public string Minor { get { return "3"; } }
54-
public string Patch { get { return "4"; } }
55-
public string PreReleaseTag { get { return "beta.5"; } }
56-
public string PreReleaseTagWithDash { get { return "-beta.5"; } }
57-
public string BuildMetaData { get { return "6"; } }
58-
public string FullBuildMetaData { get { return "6.Branch.master.Sha.commitSha"; } }
59-
public string MajorMinorPatch { get { return "2.3.4"; } }
60-
public string SemVer { get { return "2.3.4-beta.5"; } }
61-
public string LegacySemVer { get { return "2.3.4-beta5"; } }
62-
public string LegacySemVerPadded { get { return "2.3.4-beta0005"; } }
63-
public string AssemblySemVer { get { return "2.0.0.0"; } }
64-
public string FullSemVer { get { return "2.3.4-beta.5+6"; } }
65-
public string InformationalVersion { get { return "2.3.4-beta.5+6.Branch.master.Sha.commitSha"; } }
66-
public string BranchName { get { return "master"; } }
67-
public string Sha { get { return "commitSha"; } }
68-
public string NuGetVersionV2 { get { return "2.3.4-beta0005"; } }
69-
public string NuGetVersion { get { return "2.3.4-beta0005"; } }
70-
public string CommitDate { get { return "2014-03-06"; } }
71-
}
7235
}

src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,9 @@ using System.Reflection;
44
[assembly: AssemblyVersion("2.3.0.0")]
55
[assembly: AssemblyFileVersion("2.3.4.0")]
66
[assembly: AssemblyInformationalVersion("2.3.4-beta.5+6.Branch.master.Sha.commitSha")]
7-
[assembly: Fake.ReleaseDate("2014-03-06")]
8-
[assembly: Fake.GitVersionInformation()]
97

108
namespace Fake
119
{
12-
[System.Runtime.CompilerServices.CompilerGenerated]
13-
[AttributeUsage(AttributeTargets.Assembly)]
14-
sealed class ReleaseDateAttribute : System.Attribute
15-
{
16-
public string Date { get; private set; }
17-
18-
public ReleaseDateAttribute(string date)
19-
{
20-
Date = date;
21-
}
22-
}
2310

2411
[System.Runtime.CompilerServices.CompilerGenerated]
2512
static class GitVersionInformation
@@ -45,28 +32,4 @@ namespace Fake
4532
public static string CommitDate = "2014-03-06";
4633
}
4734

48-
[System.Runtime.CompilerServices.CompilerGenerated]
49-
[AttributeUsage(AttributeTargets.Assembly)]
50-
sealed class GitVersionInformationAttribute : System.Attribute
51-
{
52-
public string Major { get { return "2"; } }
53-
public string Minor { get { return "3"; } }
54-
public string Patch { get { return "4"; } }
55-
public string PreReleaseTag { get { return "beta.5"; } }
56-
public string PreReleaseTagWithDash { get { return "-beta.5"; } }
57-
public string BuildMetaData { get { return "6"; } }
58-
public string FullBuildMetaData { get { return "6.Branch.master.Sha.commitSha"; } }
59-
public string MajorMinorPatch { get { return "2.3.4"; } }
60-
public string SemVer { get { return "2.3.4-beta.5"; } }
61-
public string LegacySemVer { get { return "2.3.4-beta5"; } }
62-
public string LegacySemVerPadded { get { return "2.3.4-beta0005"; } }
63-
public string AssemblySemVer { get { return "2.3.0.0"; } }
64-
public string FullSemVer { get { return "2.3.4-beta.5+6"; } }
65-
public string InformationalVersion { get { return "2.3.4-beta.5+6.Branch.master.Sha.commitSha"; } }
66-
public string BranchName { get { return "master"; } }
67-
public string Sha { get { return "commitSha"; } }
68-
public string NuGetVersionV2 { get { return "2.3.4-beta0005"; } }
69-
public string NuGetVersion { get { return "2.3.4-beta0005"; } }
70-
public string CommitDate { get { return "2014-03-06"; } }
71-
}
7235
}

src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,9 @@ using System.Reflection;
44
[assembly: AssemblyVersion("2.3.4.0")]
55
[assembly: AssemblyFileVersion("2.3.4.0")]
66
[assembly: AssemblyInformationalVersion("2.3.4-beta.5+6.Branch.master.Sha.commitSha")]
7-
[assembly: Fake.ReleaseDate("2014-03-06")]
8-
[assembly: Fake.GitVersionInformation()]
97

108
namespace Fake
119
{
12-
[System.Runtime.CompilerServices.CompilerGenerated]
13-
[AttributeUsage(AttributeTargets.Assembly)]
14-
sealed class ReleaseDateAttribute : System.Attribute
15-
{
16-
public string Date { get; private set; }
17-
18-
public ReleaseDateAttribute(string date)
19-
{
20-
Date = date;
21-
}
22-
}
2310

2411
[System.Runtime.CompilerServices.CompilerGenerated]
2512
static class GitVersionInformation
@@ -45,28 +32,4 @@ namespace Fake
4532
public static string CommitDate = "2014-03-06";
4633
}
4734

48-
[System.Runtime.CompilerServices.CompilerGenerated]
49-
[AttributeUsage(AttributeTargets.Assembly)]
50-
sealed class GitVersionInformationAttribute : System.Attribute
51-
{
52-
public string Major { get { return "2"; } }
53-
public string Minor { get { return "3"; } }
54-
public string Patch { get { return "4"; } }
55-
public string PreReleaseTag { get { return "beta.5"; } }
56-
public string PreReleaseTagWithDash { get { return "-beta.5"; } }
57-
public string BuildMetaData { get { return "6"; } }
58-
public string FullBuildMetaData { get { return "6.Branch.master.Sha.commitSha"; } }
59-
public string MajorMinorPatch { get { return "2.3.4"; } }
60-
public string SemVer { get { return "2.3.4-beta.5"; } }
61-
public string LegacySemVer { get { return "2.3.4-beta5"; } }
62-
public string LegacySemVerPadded { get { return "2.3.4-beta0005"; } }
63-
public string AssemblySemVer { get { return "2.3.4.0"; } }
64-
public string FullSemVer { get { return "2.3.4-beta.5+6"; } }
65-
public string InformationalVersion { get { return "2.3.4-beta.5+6.Branch.master.Sha.commitSha"; } }
66-
public string BranchName { get { return "master"; } }
67-
public string Sha { get { return "commitSha"; } }
68-
public string NuGetVersionV2 { get { return "2.3.4-beta0005"; } }
69-
public string NuGetVersion { get { return "2.3.4-beta0005"; } }
70-
public string CommitDate { get { return "2014-03-06"; } }
71-
}
7235
}

0 commit comments

Comments
 (0)