I have a requirement where my string is of format as below:
<?define BuildNumber = "8314" ?>
I am using below powershell script in TFS 2017 build template to replace the build number value:
$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
This gives output like <?define BuildNumber = " 27994 " ?>
which is incorrect as I do not want spaces in the value.
When I tried using below code, it does not work.
$content -Replace '(BuildNumber\s*=\s*")\d*("\s*)', "`$1$num`$2" | Out-File $(Build.SourcesDirectory)\Install\Common\Constants.wxi
Output : <?define $27994 ?>
I tried all combinations but cannot get the quotations to work correctly. Please suggest a solution.