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 and updated UseTargetFrameworks script to accommodate submodule #109

Merged
merged 1 commit into from
Jul 19, 2023
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
23 changes: 6 additions & 17 deletions MultiTarget/UseTargetFrameworks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,9 @@
Param (
[Parameter(HelpMessage = "The target frameworks to enable.")]
[ValidateSet('all', 'all-uwp', 'wasm', 'uwp', 'winappsdk', 'wpf', 'gtk', 'macos', 'ios', 'droid', 'netstandard')]
[string[]]$targets = @('uwp', 'winappsdk', 'wasm'), # default settings

[Parameter(HelpMessage = "Disables suppressing changes to the TargetFrameworks file in git, allowing changes to be committed.")]
[switch]$allowGitChanges = $false
[string[]]$targets = @('uwp', 'winappsdk', 'wasm') # default settings
)

# Suppress git warning "core.useBuiltinFSMonitor will be deprecated soon; use core.fsmonitor instead"
& git config advice.useCoreFSMonitorConfig false;

if ($allowGitChanges.IsPresent) {
Write-Warning "Changes to the default TargetFrameworks can now be committed. Run this command again without the -allowGitChanges flag to disable committing further changes.";
git update-index --no-assume-unchanged $PSScriptRoot/EnabledTargetFrameworks.props
}
else {
Write-Output "Changes to the default TargetFrameworks are now suppressed. To switch branches, run git reset --hard with a clean working tree.";
git update-index --assume-unchanged $PSScriptRoot/EnabledTargetFrameworks.props
}

$UwpTfm = "UwpTargetFramework";
$WinAppSdkTfm = "WinAppSdkTargetFramework";
$WasmTfm = "NetStandardCommonTargetFramework";
Expand Down Expand Up @@ -112,10 +97,14 @@ if ($targets.Contains("netstandard")) {
$desiredTfmValues += $NetstandardTfm;
}

Write-Output "Setting enabled TargetFrameworks: $targets"

$targetFrameworksToRemove = $allTargetFrameworks.Where({ -not $desiredTfmValues.Contains($_) })

$targetFrameworksToRemoveRegexPartial = $targetFrameworksToRemove -join "|";

$newFileContents = $fileContents -replace "<(?:$targetFrameworksToRemoveRegexPartial)>.+?>", '';

Set-Content -Force -Path $PSScriptRoot/TargetFrameworks.props -Value $newFileContents;
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."