Skip to content

Conditional ms build tasks #687

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

Merged
merged 4 commits into from
Nov 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
45 changes: 28 additions & 17 deletions src/GitVersionTask/NugetAssets/GitVersionTask.targets
Original file line number Diff line number Diff line change
@@ -1,34 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">$(MSBuildProjectDirectory)..\</SolutionDir>
<IntermediateOutputPath Condition="$(IntermediateOutputPath) == '' Or $(IntermediateOutputPath) == '*Undefined*'">$(MSBuildProjectDirectory)obj\$(Configuration)\</IntermediateOutputPath>
<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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you removed NoFetch intentionally? This was introduced to fix #646

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An oversight - fixed

AssemblyFile="$(MSBuildThisFileDirectory)..\..\GitVersionTask.dll" />
<UsingTask
TaskName="GitVersionTask.WriteVersionInfoToBuildLog"
AssemblyFile="$(MSBuildThisFileDirectory)..\..\GitVersionTask.dll" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you removed NoFetch intentionally? This was introduced to fix #646

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No - it's a diff I didn't catch when creating a patch from my "messy" repo.


<Target Name="UpdateAssemblyInfo"
BeforeTargets="CoreCompile">
<WriteVersionInfoToBuildLog
SolutionDirectory="$(SolutionDir)"
NoFetch="$(GitVersion_NoFetchEnabled)"
/>
<Target Name="WriteVersionInfoToBuildLog" BeforeTargets="CoreCompile" Condition="$(WriteVersionInfoToBuildLog) == 'true'">
<WriteVersionInfoToBuildLog SolutionDirectory="$(SolutionDir)" NoFetch="$(GitVersion_NoFetchEnabled)"/>
</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)"
NoFetch="$(GitVersion_NoFetchEnabled)"
ProjectFile="$(MSBuildProjectFullPath)"
IntermediateOutputPath="$(IntermediateOutputPath)"
RootNamespace="$(RootNamespace)"
CompileFiles ="@(Compile)">
<Output
TaskParameter="AssemblyInfoTempFilePath"
PropertyName="AssemblyInfoTempFilePath" />
Expand All @@ -37,7 +46,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