2017-05-29 47 views
0

我想在2017年TFS創建一個版本的定義與PowerShell腳本PowerShell的 - Overiding參數RELASE定義

我乳寧說已經找setParameters.xml文件的路徑,其功能以及它PowerShell腳本假設超過所有的令牌,但它只是忽略循環和參數保持不變。

Script代碼:

$vars = Get-ChildItem -path env:* 

# read in the setParameters file 
$contents = Get-Content -Path $paramsFilePath 

# perform a regex replacement 

$newContents = ""; 
$contents | % { 
    $line = $_ 
    if ($_ -match "__(\w+)__") { 
     $setting = Get-ChildItem -path env:* | ? { $_.Name -eq $Matches[1] } 
     if ($setting) { 
      Write-Verbose -Verbose ("Replacing key {0} with value from environment" -f $setting.Name) 
      $line = $_ -replace "__(\w+)__", $setting.Value 
     } 
    } 
    $newContents += $line + [Environment]::NewLine 
} 

爲什麼環路是skiped,我怎麼能解決它,所以它會覆蓋SetParameters.xml文件中的參數呢?

+0

? Ans如何與tfs相關? – Clijsters

+0

我正在創建一個發佈定義。在TFS中...... –

+0

是的,這就是腳本。但是_你的問題_與tfs無關。 – Clijsters

回答

0

對於那些感興趣的人,我放棄了這個PowerShell,並在Release定義中使用了替換令牌步驟。

我認爲它是一種更有效的方式爲什麼要使用正則表達式替換,而不是PowerShells內置XML功能,可替換的令牌