Skip to content

Commit d71b08b

Browse files
committed
Fixed a regex issue with UseTargetFrameworks.ps1 when enabling 'all'
1 parent d61602f commit d71b08b

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

MultiTarget/UseTargetFrameworks.ps1

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ $DroidTfm = "AndroidLibTargetFramework";
4242
$NetstandardTfm = "DotnetStandardCommonTargetFramework";
4343

4444
$fileContents = Get-Content -Path $PSScriptRoot/AvailableTargetFrameworks.props
45+
$newFileContents = $fileContents;
4546

4647
# 'all' represents many '$MultiTargets' values
4748
if ($MultiTargets.Contains("all")) {
@@ -105,10 +106,12 @@ $targetFrameworksToRemove = @(
105106
$NetstandardTfm
106107
).Where({ -not $desiredTfmValues.Contains($_) })
107108

108-
$targetFrameworksToRemoveRegexPartial = $targetFrameworksToRemove -join "|";
109-
110-
$newFileContents = $fileContents -replace "<(?:$targetFrameworksToRemoveRegexPartial).+?>.+?>", '';
109+
# When targetFrameworksToRemoveRegexPartial is empty, the regex will match everything.
110+
# To work around this, check if there's anything to remove before doing it.
111+
if ($targetFrameworksToRemove.Length -gt 0) {
112+
$targetFrameworksToRemoveRegexPartial = "$($targetFrameworksToRemove -join "|")";
113+
$newFileContents = $fileContents -replace "<(?:$targetFrameworksToRemoveRegexPartial).+?>.+?>", '';
114+
}
111115

112116
Set-Content -Force -Path $PSScriptRoot/EnabledTargetFrameworks.props -Value $newFileContents;
113-
114-
Write-Output "Done. Please close and regenerate your solution. Do not commit these changes to the tooling repository."
117+
Write-Output "Done. Please close and regenerate your solution. Do not commit these changes to the tooling repository."

0 commit comments

Comments
 (0)