根据一组布尔参数创建MSBuild参数字符串 [英] Create MSBuild arguments string based on a set of boolean parameters
问题描述
作为AzureDevops用户,我希望能够通过打开和关闭运行管道"复选框来手动传递不同的MSBuild常量(通过 DefineConstants
).用户界面.
示例:
As a AzureDevops user I want to be able to manually pass different MSBuild constants (via DefineConstants
) by turning checkboxes on and off on the "Run Pipeline" UI.
Example:
我通过为当前管道定义两个布尔参数来实现这一目标:
I achieve that by defining two boolean parameters for the current pipeline:
parameters:
- name: enableDebugErrorMessages
displayName: 'Enable debug error messages'
type: boolean
default: false
- name: enableAnalytics
displayName: 'Enable analytics'
type: boolean
default: true
现在,我想为MSBuild生成一个包含启用常量的字符串.例子:
Now I want to generate a string for MSBuild containing enabled constants. Examples:
/p:DefineConstants="ENABLE_ANALYTICS"
/p:DefineConstants="ENABLE_DEBUG_MESSAGES;ENABLE_ANALYTICS"
所以我可以通过这种方式将它们传递给MSBuild:
so I can pass them for MSBuild this way:
- task: XamariniOS@2
inputs:
args: '<HERE>'
我尝试了文档除了推荐答案
更新:我在一个琐碎的管道上破解了( another ),并提出了这个解决方案: UPDATED: I took (another) crack at it on a trivial pipeline and came up with this: 当我使用Azure Pipelines展开那个文件时,我得到: When I have Azure Pipelines expand that file, I get: 离您想要的地方更近吗?您可以使用带有不同常量名称,描述和默认值的复选框. Is that closer to what you want? You can have checkboxes with different constant names, descriptions, and default values. 这篇关于根据一组布尔参数创建MSBuild参数字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!pool: MyBuildPool
parameters:
- name: ENABLE_ANALYTICS
displayName: "Analytics"
type: boolean
default: false
- name: ENABLE_DEBUG_MESSAGES
displayName: "Debug Messages"
type: boolean
default: true
- name: ENABLE_SOMETHING_ELSE
displayName: "Something Else"
type: boolean
default: false
variables:
- ${{ each p in parameters }}:
- name: "DEFINECONSTANT_${{p.key}}"
value: ${{ p.value }}
steps:
- pwsh: |
$constantVars = Get-ChildItem -Path Env:\ | Where-Object Name -like "DEFINECONSTANT_*"
$constantList = ""
$constantVars | ForEach-Object {
$constantList += "$($_.Name.Replace('DEFINECONSTANT_', ''))=$($_.Value);"
}
Write-Host "/p:DefineConstants=`"$constantList`""
displayName: 'Combine parameter values'
parameters:
- name: ENABLE_ANALYTICS
displayName: "Analytics"
type: boolean
default: false
- name: ENABLE_DEBUG_MESSAGES
displayName: "Debug Messages"
type: boolean
default: true
- name: ENABLE_SOMETHING_ELSE
displayName: "Something Else"
type: boolean
default: false
variables:
- name: DEFINECONSTANT_ENABLE_ANALYTICS
value: False
- name: DEFINECONSTANT_ENABLE_DEBUG_MESSAGES
value: True
- name: DEFINECONSTANT_ENABLE_SOMETHING_ELSE
value: False
stages:
- stage: __default
jobs:
- job: Job
pool:
name: MyPoolName
steps:
- task: PowerShell@2
displayName: 'Combine parameter values'
inputs:
targetType: inline
script: |
$constantVars = Get-ChildItem -Path Env:\ | Where-Object Name -like "DEFINECONSTANT_*"
$constantList = ""
$constantVars | ForEach-Object {
$constantList += "$($_.Name.Replace('DEFINECONSTANT_', ''))=$($_.Value);"
}
Write-Host "/p:DefineConstants=`"$constantList`""
pwsh: true