如何在 MSBuild 脚本中使用自定义变量? [英] How do I use custom variables in MSBuild scripts?
问题描述
在使用 MSBuild.exe 构建时,有没有办法在命令行上使用自定义变量,如下所示:
Is there a way to use custom variables on the command-line when building with MSBuild.exe as follows:
MSBuild.exe bootstrapper.msbuild <custom_variable1=custom_variable_value1>
custom_variable2=custom_variable_value2>...<custom_variablen=custom_variable_valuen>
目的是知道我是否必须启动另一个可执行文件.
The purpose is to know whether I have to launch another executable or not.
推荐答案
你应该从基础开始.答案可在官方文档中找到.
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
.
这篇关于如何在 MSBuild 脚本中使用自定义变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!