Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed a regex issue with UseTargetFrameworks.ps1 when enabling 'all' #224

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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."
Loading