1
1
# MSBuild Task
2
2
3
- The MSBuild Task for GitVersion — ** GitVersionTask** — a simple solution if you
4
- want to version your assemblies without writing any command line scripts or
5
- modifying your build process.
3
+ The MSBuild Task for GitVersion — ** GitVersionTask** — is a simple solution if
4
+ you want to version your assemblies without writing any command line scripts or
5
+ modifying your build process.
6
6
7
7
## TL;DR
8
8
9
9
### Install
10
10
11
11
It works simply by installing the [ GitVersionTask NuGet
12
12
Package] ( https://www.nuget.org/packages/GitVersionTask/ ) into the project you
13
- want to have versioned by GitVersion:
13
+ want to have versioned by GitVersion:
14
14
15
- Install-Package GitVersionTask
15
+ ``` shell
16
+ Install-Package GitVersionTask
17
+ ```
16
18
17
19
### Remove attributes
18
20
19
21
The next thing you need to do, is remove the ` Assembly*Version ` attributes from
20
22
your ` Properties\AssemblyInfo.cs ` files, so GitVersionTask can be in charge of
21
- versioning your assemblies.
23
+ versioning your assemblies.
22
24
23
25
### Done!
24
26
@@ -32,7 +34,7 @@ described below.
32
34
33
35
## How does it work?
34
36
35
- ### Inject version metadata into the assembly
37
+ ### Inject version metadata into the assembly
36
38
37
39
The sub-task named ` GitVersionTask.UpdateAssemblyInfo ` will inject version
38
40
metadata into the assembly which GitVersionTask is added to. For each assembly
@@ -45,7 +47,7 @@ At build time a temporary `AssemblyInfo.cs` will be created that contains the
45
47
appropriate SemVer information. This will be included in the build pipeline.
46
48
Sample default:
47
49
48
- ``` c#
50
+ ``` csharp
49
51
[assembly : AssemblyVersion (" 1.0.0.0" )]
50
52
[assembly : AssemblyFileVersion (" 1.0.0.0" )]
51
53
[assembly : AssemblyInformationalVersion (" 1.1.0+Branch.master.Sha.722aad3217bd49a6576b6f82f60884e612f9ba58" )]
@@ -56,32 +58,32 @@ Now when you build:
56
58
* ` AssemblyVersion ` will be set to the ` AssemblySemVer ` variable.
57
59
* ` AssemblyFileVersion ` will be set to the ` MajorMinorPatch ` variable with a
58
60
* appended ` .0 ` . ` AssemblyInformationalVersion ` will be set to the
59
- * ` InformationalVersion ` variable.
61
+ * ` InformationalVersion ` variable.
60
62
61
63
#### Other injected Variables
62
64
63
65
All other [ variables] ( ../more-info/variables.md ) will be injected into an
64
- internal static class:
66
+ internal static class:
65
67
66
- ``` c#
68
+ ``` csharp
67
69
namespace AssemblyName
68
70
{
69
- [CompilerGenerated ]
70
- internal static class GitVersionInformation
71
- {
72
- public static string Major = " 1" ;
73
- public static string Minor = " 1" ;
74
- public static string Patch = " 0" ;
75
- ...All other variables
76
- }
71
+ [CompilerGenerated ]
72
+ internal static class GitVersionInformation
73
+ {
74
+ public static string Major = " 1" ;
75
+ public static string Minor = " 1" ;
76
+ public static string Patch = " 0" ;
77
+ ...All other variables
78
+ }
77
79
}
78
80
```
79
81
80
82
#### Accessing injected Variables
81
83
82
84
##### All variables
83
85
84
- ```c#
86
+ ```csharp
85
87
var assemblyName = assembly.GetName().Name;
86
88
var gitVersionInformationType = assembly.GetType(assemblyName + ".GitVersionInformation");
87
89
var fields = gitVersionInformationType.GetFields();
@@ -94,7 +96,7 @@ foreach (var field in fields)
94
96
95
97
##### Specific variable
96
98
97
- ``` c#
99
+ ``` csharp
98
100
var assemblyName = assembly .GetName ().Name ;
99
101
var gitVersionInformationType = assembly .GetType (assemblyName + " .GitVersionInformation" );
100
102
var versionField = gitVersionInformationType .GetField (" Major" );
@@ -118,7 +120,7 @@ After `GitVersionTask.GetVersion` has executed, the MSBuild properties can be
118
120
used in the standard way. For example:
119
121
120
122
``` xml
121
- <Message Text =" GitVersion_InformationalVersion: $(GitVersion_InformationalVersion)" />
123
+ <Message Text =" GitVersion_InformationalVersion: $(GitVersion_InformationalVersion)" />
122
124
```
123
125
124
126
### Communicate variables to current Build Server
@@ -129,7 +131,7 @@ the version information to the current Build Server log.
129
131
If, at build time, it is detected that the build is occurring inside a Build
130
132
Server then the [ variables] ( ../more-info/variables.md ) will be written to the
131
133
Build Server log in a format that the current Build Server can consume. See
132
- [ Build Server Support] ( ../build-server-support/build-server-support.md ) .
134
+ [ Build Server Support] ( ../build-server-support/build-server-support.md ) .
133
135
134
136
## Conditional control tasks
135
137
@@ -147,7 +149,7 @@ this:
147
149
...
148
150
</PropertyGroup >
149
151
```
150
-
152
+
151
153
## My Git repository requires authentication. What do I do?
152
154
153
155
Set the environmental variables ` GITVERSION_REMOTE_USERNAME ` and
0 commit comments