I would like to change the value of a property if it is a certain value. In C# I would write:
if(x=="NotAllowed")
x="CorrectedValue;
This is what I have so far, please don't laugh:
<PropertyGroup>
<BranchName>BranchNameNotSet</BranchName>
</PropertyGroup>
///Other targets set BranchName
<Target Name="CheckPropertiesHaveBeenSet">
<Error Condition="$(BranchName)==BranchNameNotSet" Text="Something has gone wrong.. branch name not entered"/>
<When Condition="$(BranchName)==master">
<PropertyGroup>
<BranchName>MasterBranch</BranchName>
</PropertyGroup>
</When>
</Target>
You can do that using Condition
on Property
:
<PropertyGroup>
<BranchName>BranchNameNotSet</BranchName>
</PropertyGroup>
<Target Name="CheckPropertiesHaveBeenSet">
<!-- If BranchName equals 'BranchNameNotSet' stop the build with error-->
<Error Condition="'$(BranchName)'=='BranchNameNotSet'" Text="Something has gone wrong.. branch name not entered"/>
<PropertyGroup>
<!-- Change BranchName value if BranchName equals 'master' -->
<BranchName Condition="'$(BranchName)'=='master'">MasterBranch</BranchName>
</PropertyGroup>
</Target>
When
and Choose
:The Choose, When, and Otherwise elements are used together to provide a way to select one section of code to execute out of a number of possible alternatives.
Choose elements can be used as child elements of Project, When and Otherwise elements.
In your code sample, you use When
without Choose
and within a target, that is not possible.
this sets BranchName to the string 'CorrectedValue' if it's value equals 'NotAllowed':
<PropertyGroup>
<BranchName Condition="'$(BranchName)'=='NotAllowed'">CorrectedValue</BranchName>
</PropertyGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With