Skip to content

Commit caa2d78

Browse files
committed
Fixed issue with -NoNewline not working in PS4
1 parent 9a1977b commit caa2d78

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

RegexReplace/RegexReplace.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ Trace-VstsEnteringInvocation $MyInvocation
1616
try {
1717
Import-VstsLocStrings "$PSScriptRoot\task.json"
1818

19+
# Check Powershell Version
20+
if ($PSVersionTable.PSCompatibleVersions -notcontains '4.0')
21+
{
22+
Write-VstsTaskError "This task requires Powershell 4.0 or later"
23+
exit;
24+
}
25+
1926
$inputSearchPattern = (Get-VstsInput -Name InputSearchPattern -Require)
2027
$useUTF8 = Get-VstsInput -Name UseUTF8 -AsBool -Require
2128
$useRaw = Get-VstsInput -Name UseRAW -AsBool -Require
@@ -47,7 +54,14 @@ try {
4754
Write-Host "Replacing $findRegex with $replaceRegex ($ext)"
4855

4956
foreach ($path in $inputPaths) {
50-
$setContentParams = @{ Path = $path; NoNewLine = $true }
57+
$setContentParams = @{ Path = $path; }
58+
59+
# NoNewline is only available in Powershell >= 5.0
60+
if ($PSVersionTable.PSCompatibleVersions -contains '5.0')
61+
{
62+
$setContentParams.Add("NoNewline", $true);
63+
}
64+
5165
$getContentParams = @{ Path = $path }
5266

5367
Write-Host "...in file $path"

0 commit comments

Comments
 (0)