Skip to content

Conditional ms build tasks #676

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
14 changes: 14 additions & 0 deletions docs/usage/msbuild-task.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ Task Name: `GitVersionTask.WriteVersionInfoToBuildLog`

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

## Conditional control tasks

Properties `WriteVersionInfoToBuildLog`, `UpdateAssemblyInfo` and `GetVersion` are checked before running these tasks.

If you, eg., want to disable `GitVersionTask.UpdateAssemblyInfo` just define `UpdateAssemblyInfo` to something other than `true` in your MSBuild script, like this:

```
<PropertyGroup>
...
<UpdateAssemblyInfo>false</UpdateAssemblyInfo>
...
</PropertyGroup>
```

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

Set the environmental variables `GITVERSION_REMOTE_USERNAME` and `GITVERSION_REMOTE_PASSWORD` before the build is initiated.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public class VersionInBranchBaseVersionStrategyTests
[TestCase("release/2.0.0", "2.0.0")]
[TestCase("hotfix-2.0.0", "2.0.0")]
[TestCase("hotfix/2.0.0", "2.0.0")]
[TestCase("hotfix/2.0.0", "2.0.0")]
[TestCase("custom/JIRA-123", null)]
public void CanTakeVersionFromBranchName(string branchName, string expectedBaseVersion)
{
Expand Down
40 changes: 25 additions & 15 deletions src/GitVersionTask/NugetAssets/GitVersionTask.targets
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,39 @@
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)..\</SolutionDir>
<IntermediateOutputPath Condition="$(IntermediateOutputPath) == '' Or $(IntermediateOutputPath) == '*Undefined*'">$(MSBuildProjectDirectory)obj\$(Configuration)\</IntermediateOutputPath>
<GitVersion_NoFetchEnabled Condition="$(GitVersion_NoFetchEnabled) == ''">false</GitVersion_NoFetchEnabled>

<!-- Property that enables WriteVersionInfoToBuildLog -->
<WriteVersionInfoToBuildLog Condition=" '$(WriteVersionInfoToBuildLog)' == '' ">true</WriteVersionInfoToBuildLog>

<!-- Property that enables UpdateAssemblyInfo -->
<UpdateAssemblyInfo Condition=" '$(UpdateAssemblyInfo)' == '' ">true</UpdateAssemblyInfo>

<!-- Property that enables GetVersion -->
<GetVersion Condition=" '$(GetVersion)' == '' ">true</GetVersion>

</PropertyGroup>

<UsingTask
TaskName="GitVersionTask.UpdateAssemblyInfo"
AssemblyFile="$(MSBuildThisFileDirectory)..\..\GitVersionTask.dll" />
<UsingTask
TaskName="GitVersionTask.GetVersion"
<UsingTask
TaskName="GitVersionTask.GetVersion"
AssemblyFile="$(MSBuildThisFileDirectory)..\..\GitVersionTask.dll" />
<UsingTask
TaskName="GitVersionTask.WriteVersionInfoToBuildLog"
AssemblyFile="$(MSBuildThisFileDirectory)..\..\GitVersionTask.dll" />

<Target Name="UpdateAssemblyInfo"
BeforeTargets="CoreCompile">
<WriteVersionInfoToBuildLog
SolutionDirectory="$(SolutionDir)"
NoFetch="$(GitVersion_NoFetchEnabled)"
/>
<Target Name="WriteVersionInfoToBuildLog" BeforeTargets="CoreCompile" Condition="$(WriteVersionInfoToBuildLog) == 'true'">
<WriteVersionInfoToBuildLog SolutionDirectory="$(SolutionDir)" />
</Target>

<Target Name="UpdateAssemblyInfo" BeforeTargets="CoreCompile" Condition="$(UpdateAssemblyInfo) == 'true'">
<UpdateAssemblyInfo
SolutionDirectory="$(SolutionDir)"
NoFetch="$(GitVersion_NoFetchEnabled)"
ProjectFile="$(MSBuildProjectFullPath)"
IntermediateOutputPath="$(IntermediateOutputPath)"
RootNamespace="$(RootNamespace)"
CompileFiles ="@(Compile)">
SolutionDirectory="$(SolutionDir)"
ProjectFile="$(MSBuildProjectFullPath)"
IntermediateOutputPath="$(IntermediateOutputPath)"
RootNamespace="$(RootNamespace)"
CompileFiles ="@(Compile)">
<Output
TaskParameter="AssemblyInfoTempFilePath"
PropertyName="AssemblyInfoTempFilePath" />
Expand All @@ -37,7 +45,9 @@
<ItemGroup>
<Compile Include="$(AssemblyInfoTempFilePath)" />
</ItemGroup>

</Target>

<Target Name="GetVersion" BeforeTargets="CoreCompile" Condition="$(GetVersion) == 'true'">

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