Skip to content

Commit 1b8d18d

Browse files
author
Frode Nilsens
committed
Added MSBuild properties to control running of GitVersionTasks
1 parent fd77425 commit 1b8d18d

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

docs/usage/msbuild-task.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@ Task Name: `GitVersionTask.WriteVersionInfoToBuildLog`
8888

8989
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).
9090

91+
## Conditional control tasks
92+
93+
Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo` and `GetVersion` are checked before running these tasks.
94+
95+
If you, eg., want to disable `GitVersionTask.UpdateAssemblyInfo` just define `UpdateAssemblyInfo` to something other than `true` in your MSBuild script, like this:
96+
97+
```
98+
<PropertyGroup>
99+
...
100+
<UpdateAssemblyInfo>false</UpdateAssemblyInfo>
101+
...
102+
</PropertyGroup>
103+
```
104+
91105
## My Git repository requires authentication. What do I do?
92106

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

src/GitVersionTask/NugetAssets/GitVersionTask.targets

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,39 @@
44
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)..\</SolutionDir>
55
<IntermediateOutputPath Condition="$(IntermediateOutputPath) == '' Or $(IntermediateOutputPath) == '*Undefined*'">$(MSBuildProjectDirectory)obj\$(Configuration)\</IntermediateOutputPath>
66
<GitVersion_NoFetchEnabled Condition="$(GitVersion_NoFetchEnabled) == ''">false</GitVersion_NoFetchEnabled>
7+
8+
<!-- Property that enables WriteVersionInfoToBuildLog -->
9+
<WriteVersionInfoToBuildLog Condition=" '$(WriteVersionInfoToBuildLog)' == '' ">true</WriteVersionInfoToBuildLog>
10+
11+
<!-- Property that enables UpdateAssemblyInfo -->
12+
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' ">true</UpdateAssemblyInfo>
13+
14+
<!-- Property that enables GetVersion -->
15+
<GetVersion Condition=" '$(GetVersion)' == '' ">true</GetVersion>
16+
717
</PropertyGroup>
818

919
<UsingTask
1020
TaskName="GitVersionTask.UpdateAssemblyInfo"
1121
AssemblyFile="$(MSBuildThisFileDirectory)..\..\GitVersionTask.dll" />
12-
<UsingTask
13-
TaskName="GitVersionTask.GetVersion"
22+
<UsingTask
23+
TaskName="GitVersionTask.GetVersion"
1424
AssemblyFile="$(MSBuildThisFileDirectory)..\..\GitVersionTask.dll" />
1525
<UsingTask
1626
TaskName="GitVersionTask.WriteVersionInfoToBuildLog"
1727
AssemblyFile="$(MSBuildThisFileDirectory)..\..\GitVersionTask.dll" />
1828

19-
<Target Name="UpdateAssemblyInfo"
20-
BeforeTargets="CoreCompile">
21-
<WriteVersionInfoToBuildLog
22-
SolutionDirectory="$(SolutionDir)"
23-
NoFetch="$(GitVersion_NoFetchEnabled)"
24-
/>
29+
<Target Name="WriteVersionInfoToBuildLog" BeforeTargets="CoreCompile" Condition="$(WriteVersionInfoToBuildLog) == 'true'">
30+
<WriteVersionInfoToBuildLog SolutionDirectory="$(SolutionDir)" />
31+
</Target>
32+
33+
<Target Name="UpdateAssemblyInfo" BeforeTargets="CoreCompile" Condition="$(UpdateAssemblyInfo) == 'true'">
2534
<UpdateAssemblyInfo
26-
SolutionDirectory="$(SolutionDir)"
27-
NoFetch="$(GitVersion_NoFetchEnabled)"
28-
ProjectFile="$(MSBuildProjectFullPath)"
29-
IntermediateOutputPath="$(IntermediateOutputPath)"
30-
RootNamespace="$(RootNamespace)"
31-
CompileFiles ="@(Compile)">
35+
SolutionDirectory="$(SolutionDir)"
36+
ProjectFile="$(MSBuildProjectFullPath)"
37+
IntermediateOutputPath="$(IntermediateOutputPath)"
38+
RootNamespace="$(RootNamespace)"
39+
CompileFiles ="@(Compile)">
3240
<Output
3341
TaskParameter="AssemblyInfoTempFilePath"
3442
PropertyName="AssemblyInfoTempFilePath" />
@@ -37,7 +45,9 @@
3745
<ItemGroup>
3846
<Compile Include="$(AssemblyInfoTempFilePath)" />
3947
</ItemGroup>
40-
48+
</Target>
49+
50+
<Target Name="GetVersion" BeforeTargets="CoreCompile" Condition="$(GetVersion) == 'true'">
4151

4252
<GetVersion SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersion_NoFetchEnabled)">
4353
<Output TaskParameter="Major" PropertyName="GitVersion_Major" />

0 commit comments

Comments
 (0)