如何在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屋!