Skip to content

Commit 3d421be

Browse files
committed
Merge pull request #687 from pi3k14/ConditionalMSBuildTasks
Conditional ms build tasks
2 parents 917a646 + d98e59d commit 3d421be

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
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/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/GitVersionCore.Tests/VersionCalculation/Strategies/VersionInBranchBaseVersionStrategyTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public class VersionInBranchBaseVersionStrategyTests
1515
[TestCase("release/2.0.0", "2.0.0")]
1616
[TestCase("hotfix-2.0.0", "2.0.0")]
1717
[TestCase("hotfix/2.0.0", "2.0.0")]
18-
[TestCase("hotfix/2.0.0", "2.0.0")]
1918
[TestCase("custom/JIRA-123", null)]
2019
public void CanTakeVersionFromBranchName(string branchName, string expectedBaseVersion)
2120
{

src/GitVersionTask/NugetAssets/GitVersionTask.targets

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,43 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
4-
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)..\</SolutionDir>
5-
<IntermediateOutputPath Condition="$(IntermediateOutputPath) == '' Or $(IntermediateOutputPath) == '*Undefined*'">$(MSBuildProjectDirectory)obj\$(Configuration)\</IntermediateOutputPath>
4+
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)\..\</SolutionDir>
5+
<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)" NoFetch="$(GitVersion_NoFetchEnabled)"/>
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+
NoFetch="$(GitVersion_NoFetchEnabled)"
37+
ProjectFile="$(MSBuildProjectFullPath)"
38+
IntermediateOutputPath="$(IntermediateOutputPath)"
39+
RootNamespace="$(RootNamespace)"
40+
CompileFiles ="@(Compile)">
3241
<Output
3342
TaskParameter="AssemblyInfoTempFilePath"
3443
PropertyName="AssemblyInfoTempFilePath" />
@@ -37,7 +46,9 @@
3746
<ItemGroup>
3847
<Compile Include="$(AssemblyInfoTempFilePath)" />
3948
</ItemGroup>
40-
49+
</Target>
50+
51+
<Target Name="GetVersion" BeforeTargets="CoreCompile" Condition="$(GetVersion) == 'true'">
4152

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

0 commit comments

Comments
 (0)