Skip to content

Commit

Permalink
Fixed a regex issue with UseTargetFrameworks.ps1 when enabling 'all'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arlodotexe committed Oct 29, 2024
1 parent d61602f commit d71b08b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions MultiTarget/UseTargetFrameworks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $DroidTfm = "AndroidLibTargetFramework";
$NetstandardTfm = "DotnetStandardCommonTargetFramework";

$fileContents = Get-Content -Path $PSScriptRoot/AvailableTargetFrameworks.props
$newFileContents = $fileContents;

# 'all' represents many '$MultiTargets' values
if ($MultiTargets.Contains("all")) {
Expand Down Expand Up @@ -105,10 +106,12 @@ $targetFrameworksToRemove = @(
$NetstandardTfm
).Where({ -not $desiredTfmValues.Contains($_) })

$targetFrameworksToRemoveRegexPartial = $targetFrameworksToRemove -join "|";

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

Set-Content -Force -Path $PSScriptRoot/EnabledTargetFrameworks.props -Value $newFileContents;

Write-Output "Done. Please close and regenerate your solution. Do not commit these changes to the tooling repository."
Write-Output "Done. Please close and regenerate your solution. Do not commit these changes to the tooling repository."

0 comments on commit d71b08b

Please sign in to comment.