在变量/属性中保存msbuild条件
我有一个相当长的条件,用于几个后续的构建任务,所有这些任务都在条件为真时运行,在条件为假时不运行,如下所示:在变量/属性中保存msbuild条件,msbuild,Msbuild,我有一个相当长的条件,用于几个后续的构建任务,所有这些任务都在条件为真时运行,在条件为假时不运行,如下所示: <!-- In the middle of a Target --> <Copy Condition="'$(MyProperty1)' == 'true' and '$(AnotherProperty)' == 'false' and '@(YetAnotherProperty)' != ''" ... /> <Exec Condition="'$(MyP
<!-- In the middle of a Target -->
<Copy Condition="'$(MyProperty1)' == 'true' and '$(AnotherProperty)' == 'false' and '@(YetAnotherProperty)' != ''" ... />
<Exec Condition="'$(MyProperty1)' == 'true' and '$(AnotherProperty)' == 'false' and '@(YetAnotherProperty)' != ''" ... />
<CustomTask Condition="'$(MyProperty1)' == 'true' and '$(AnotherProperty)' == 'false' and '@(YetAnotherProperty)' != ''" ... />
这是相当烦人的尝试和阅读。是否有可能以某种方式将此条件“保存”到某种类型的变量或属性中?比如:
MyVariable = "'$(MyProperty1)' == 'true' and '$(AnotherProperty)' == 'false' and '@(YetAnotherProperty)' != ''"
<Copy Condition="MyVariable" ... />
<Exec Condition="MyVariable" ... />
<CustomTask Condition="MyVariable" ... />
MyVariable=“$(MyProperty1)”=='true'和'$(AnotherProperty)=='false'和'@(YetAnotherProperty)'='
我确实找到了“Choose”元素,但目标中不允许使用它,因此它不起作用。如果我正确理解了您的需求,我认为您需要的只是定义一个属性
<PropertyGroup>
<MyProperty>False</MyProperty> <!-- defaulting to false -->
<MyProperty Condition="...Some long condition...">True</MyProperty>
</PropertyGroup>
假的
真的
……以后
<Copy Condition="$(MyProperty)" ... />
(但请注意,这是否适用于您的具体情况可能取决于条件的内容,因为MSBuild计算属性与项的顺序不同。)