且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在MSBuild脚本中使用自定义变量?

更新时间:2023-09-22 20:11:16

您应该从基础开始.答案可在官方文档中找到.

You should start with the basics. The answer is found in the official documentation.

MSBuild调用这些properties而不是变量.

MSBuild calls these properties instead of variables.

在实践中:

msbuild bootstrapper.msbuild /p:custom_variable1=custom_variable_value1

在MSBuild文件中,您可以这样使用它:

And in the MSBuild file you could use it as such:

<Target Name="MyTarget">
  <PropertyGroup>
    <custom_variable1 Condition="'$(custom_variable1) == ''">defaultValue</custom_variable1>
  </PropertyGroup>
  <Exec Condition="'$(custom_variable1)'=='someValue'" .../>
</Target>

如果属性不存在或为空,则为该属性分配默认值,并且如果该值等于someValue,则仅执行Exec任务.

This assigns a default value to the property if it doesn't exist or is empty, and only executes the Exec task if the value is equal to someValue.