我有一个要求,我的字符串格式如下:
<?define BuildNumber = "8314" ?>
我在 TFS 2017 构建模板中使用以下 powershell 脚本来替换内部版本号值:
$content = Get-Content -path "$(Build.SourcesDirectory)\Install\Common\Constants.wxi"
$num = $(Build.BuildId)
$content -Replace '(BuildNumber\s*=\s*")\d*("\s*)', "`$1 $num `$2" | Out-File $(Build.SourcesDirectory)\Install\Common\Constants.wxi
这给出了<?define BuildNumber = " 27994 " ?>
不正确的输出,因为我不希望值中有空格。当我尝试使用下面的代码时,它不起作用。
$content -Replace '(BuildNumber\s*=\s*")\d*("\s*)', "`$1$num`$2" | Out-File $(Build.SourcesDirectory)\Install\Common\Constants.wxi
输出 :<?define $27994 ?>
我尝试了所有组合,但无法让报价正常工作。请提出解决方案。