将XAML Post构建参数中的参数读入Powershell脚本

时间:2017-07-26 06:37:19

标签: xml git powershell xaml tfs

我有一个PowerShell脚本,它根据'类型'读取节点值。从XML属性文件,现在我想读取一个参数' type'来自TFS Git XAML构建过程的节点值。如何在XAML构建过程中声明一个参数并在构建脚本时读取它?

$env="Read from XAML build Process"

$xmlDocPath="D:\*****\ScriptsConfig.xml";
[xml]$xmlFile = Get-Content $xmlDocPath;
$PathToDropUIcssandjss=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty PathToDropUIcssandjss
$DeployingPackageBranchFolderName=$xml.Objects.Object | Where-Object {$_.type -eq $args[0]} | Select-Object -ExpandProperty DeployingPackageBranchFolderName
$BranchName=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty BranchName
$ProjectName=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty ProjectName
$Automation=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty Automation
$DeploymentEnvironment=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty DeploymentEnvironment

1 个答案:

答案 0 :(得分:0)

我现在可以通过以下命令从TFS读取参数

  [CmdletBinding()]
    param([string]$args)

    $env=[string]$args

但参数$ env在下面显示的命令中不起作用,但是如果我单独显示它,它在这个块之外工作

$SourceDir = $Env:TF_BUILD_SOURCESDIRECTORY
$xmlDocPath="$SourceDir\ScriptsConfig.xml";
[xml]$xmlFile = Get-Content $xmlDocPath;
$PathToDropUIcssandjss=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty PathToDropUIcssandjss
$DeployingPackageBranchFolderName=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty DeployingPackageBranchFolderName
$BranchName=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty BranchName
$ProjectName=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty ProjectName
$Automation=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty Automation
$DeploymentEnvironment=$xml.Objects.Object | Where-Object {$_.type -eq $env} | Select-Object -ExpandProperty DeploymentEnvironment