如何更改属性';基于msbuild中的条件的s值?

如何更改属性';基于msbuild中的条件的s值?,msbuild,Msbuild,我想改变一个财产的价值,如果它是一个特定的价值。我会用C#写下: if(x=="NotAllowed") x="CorrectedValue; 这就是我到目前为止所做的,请不要笑: <PropertyGroup> <BranchName>BranchNameNotSet</BranchName> </PropertyGroup> ///Other targets set BranchName <Target Name

我想改变一个财产的价值,如果它是一个特定的价值。我会用C#写下:

if(x=="NotAllowed")
  x="CorrectedValue;
这就是我到目前为止所做的,请不要笑:

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

分支菜单集
///为我设定的其他目标
母枝

如果BranchName的值等于“NotAllowed”,则将其设置为字符串“CorrectedValue”:

<PropertyGroup>
   <BranchName Condition="'$(BranchName)'=='NotAllowed'">CorrectedValue</BranchName>
</PropertyGroup>

修正值

您可以使用
属性上的
条件执行此操作:

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

分支菜单集
母枝
和选择
时有关
的信息:
Choose、When和Others元素一起使用,以提供一种从许多可能的备选方案中选择要执行的一段代码的方法

选择元素可以用作项目的子元素,如果是,则选择元素


在您的代码示例中,当
没有选择并且在一个目标内时,您使用
,这是不可能的。

谢谢madgnome,我将它提供给您,因为您明确表示propertygroup位于我的目标内