Moved to updating TFMs outside MSBuild exclusively

This commit is contained in:
Arlo Godfrey 2022-04-08 15:40:16 -05:00
Родитель 7a98d3c8a4
Коммит ca8b6a9d31
11 изменённых файлов: 95 добавлений и 91 удалений

6
.gitignore поставляемый
Просмотреть файл

@ -349,8 +349,4 @@ healthchecksdb
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Ignored as part of the Labs builds process
Common/Labs.TargetFrameworks.props*
Common/Scripts/UpdateTargetFrameworks.CurrentVariant.*
.ionide/

Просмотреть файл

@ -1,26 +0,0 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove(directory.build.props))" Condition="Exists('$([MSBuild]::GetPathOfFileAbove(directory.build.props))')" />
<PropertyGroup>
<DisableFastUpToDateCheck>True</DisableFastUpToDateCheck>
</PropertyGroup>
<Target Name="CleanupConditionalTargetFrameworkCache" BeforeTargets="Clean">
<Delete Files="$(RepositoryDirectory)Common/Scripts/UpdateTargetFrameworks.CurrentVariant.txt" />
</Target>
<Target Name="PruneExtraTargetFrameworks" BeforeTargets="PreBuildEvent">
<PropertyGroup>
<PowerShellCommand Condition=" '$(OS)' == 'Windows_NT' ">powershell</PowerShellCommand>
<PowerShellCommand Condition=" '$(OS)' == 'Unix' ">pwsh</PowerShellCommand>
</PropertyGroup>
<PropertyGroup>
<LabsTargetPlatformsVariant Condition="'$(SolutionName)' == 'Toolkit.Labs.All'">All</LabsTargetPlatformsVariant>
<LabsTargetPlatformsVariant Condition="'$(SolutionName)' == 'Toolkit.Labs.Wasm'">Wasm</LabsTargetPlatformsVariant>
<LabsTargetPlatformsVariant Condition="'$(LabsTargetPlatformsVariant)' == ''">Windows</LabsTargetPlatformsVariant>
</PropertyGroup>
<Exec Command="$(PowerShellCommand) -ExecutionPolicy Unrestricted -NoProfile -File $(RepositoryDirectory)Common/Scripts/UpdateTargetFrameworks.ps1 $(LabsTargetPlatformsVariant) --Verbose" WorkingDirectory="$(RepositoryDirectory)Common/Scripts/" />
</Target>
</Project>

Просмотреть файл

@ -1,7 +1,5 @@
<!-- Common props for any deployable sample project head. -->
<Project InitialTargets="PruneExtraTargetFrameworks">
<Import Project="$(RepositoryDirectory)Common\ConditionalTargetFramework.targets" />
<Project>
<!-- Shared project -->
<Import Project="$(RepositoryDirectory)Common\CommunityToolkit.Labs.Shared\CommunityToolkit.Labs.Shared.projitems" Label="Shared" />

Просмотреть файл

@ -1,6 +1,4 @@
<Project InitialTargets="PruneExtraTargetFrameworks;ValidateWinUITarget">
<Import Project="$(RepositoryDirectory)Common\ConditionalTargetFramework.targets" />
<Project InitialTargets="ValidateWinUITarget">
<Import Project="Labs.TargetFrameworks.props" />
<PropertyGroup>

Просмотреть файл

@ -0,0 +1,17 @@
<Project>
<PropertyGroup>
<UwpTargetFramework>uap10.0.17763</UwpTargetFramework>
<WinAppSdkTargetFramework>net6.0-windows10.0.19041.0</WinAppSdkTargetFramework>
<WasmHeadTargetFramework>net5.0</WasmHeadTargetFramework>
<LinuxHeadTargetFramework>net5.0</LinuxHeadTargetFramework>
<WpfHeadTargetFramework>netcoreapp3.1</WpfHeadTargetFramework>
<WasmLibTargetFramework>netstandard2.0</WasmLibTargetFramework>
<WpfLibTargetFramework>netstandard2.0</WpfLibTargetFramework>
</PropertyGroup>
</Project>

Просмотреть файл

@ -1,7 +1,7 @@
<Project>
<!-- Common properties needed for a labs project (WinAppSdk) -->
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(RepositoryDirectory)Common\Labs.TargetFrameworks.default.props" />
<Import Project="$(RepositoryDirectory)Common\Labs.TargetFrameworks.All.props" />
<PropertyGroup>
<OutputType>WinExe</OutputType>

Просмотреть файл

@ -1,51 +0,0 @@
# This file can execute in parallel, causing potential file access issues.
# This lock prevent us from reading or writing concurrently and getting access exceptions.
if (Test-Path ".\..\Labs.TargetFrameworks.props.lock") {
return;
}
if ($args.Length -eq 0 -or ![bool]$args[0]) {
Write-Error "Missing parameter. Please supply a variant value of All, Wasm or Windows.";
exit(-1);
}
$variant = $args[0];
# MSBuild uses the SolutionName to determine the variant, but SolutionName occassionally goes missing during
# the build process, which causes the default/fallback variant to be used when it shouldn't.
# This check ensures we're always using the same variant, until the file is deleted by MSBuild during a clean.
if ((Get-Content -Path .\UpdateTargetFrameworks.CurrentVariant.txt).Trim() -notlike $variant) {
# for debug only
Set-Content -Path .\UpdateTargetFrameworks.CircumventedVariant.$variant.txt -Value '';
return;
}
Set-Content -Path .\UpdateTargetFrameworks.CurrentVariant.txt -Value $variant;
Set-Content -Path .\..\Labs.TargetFrameworks.props.lock -Value '';
$fileContents = Get-Content -Path .\..\Labs.TargetFrameworks.default.props
if ($variant -eq "All") {
# If set to All, don't do any replacements and copy all TFMs.
$newFileContents = $fileContents;
}
if ($variant -eq "Wasm") {
# Remove all non-wasm TFMs
$newFileContents = $fileContents -replace '<(UwpTargetFramework|WinAppSdkTargetFramework|WpfLibTargetFramework|LinuxLibTargetFramework|AndroidLibTargetFramework|MacOSLibTargetFramework|iOSLibTargetFramework)>.+?>', '';
}
if ($variant -eq "Windows") {
# Minimal Windows dependencies.
$newFileContents = $fileContents -replace '<(LinuxLibTargetFramework|AndroidLibTargetFramework|MacOSLibTargetFramework|iOSLibTargetFramework)>.+?>', '';
}
# MSBuild uses last modified date instead of file hashes to determine when the content has changed.
# Only update the props file if the new content is different.
if ($newFileContents -eq $fileContents) {
Remove-Item -Path .\..\Labs.TargetFrameworks.props.lock;
return;
}
Set-Content -Force -Path .\..\Labs.TargetFrameworks.props -Value $newFileContents;
Remove-Item -Path .\..\Labs.TargetFrameworks.props.lock;

Просмотреть файл

@ -0,0 +1,72 @@
if ($args.Length -eq 0 -or ![bool]$args[0]) {
Write-Error "Please supply one or more arguments. Valid values are all, wasm, uwp, winappsdk, wpf, gtk, macos, ios, and droid.";
exit(-1);
}
$WasmTfm = "WasmLibTargetFramework";
$UwpTfm = "UwpTargetFramework";
$WinAppSdkTfm = "WinAppSdkTargetFramework";
$WpfTfm = "WpfLibTargetFramework";
$GtkTfm = "LinuxLibTargetFramework";
$macOSTfm = "MacOSLibTargetFramework";
$iOSTfm = "iOSLibTargetFramework";
$DroidTfm = "AndroidLibTargetFramework";
$fileContents = Get-Content -Path .\..\Labs.TargetFrameworks.All.props
$allTargetFrameworks = @(
$WasmTfm,
$UwpTfm,
$WinAppSdkTfm,
$WpfTfm,
$GtkTfm,
$macOSTfm,
$iOSTfm,
$DroidTfm
);
$desiredTfmValues = @();
if ($args.Contains("all")) {
$desiredTfmValues = $allTargetFrameworks;
}
if ($args.Contains("wasm")) {
$desiredTfmValues += $WasmTfm;
}
if ($args.Contains("uwp")) {
$desiredTfmValues += $UwpTfm;
}
if ($args.Contains("winappsdk")) {
$desiredTfmValues += $WinAppSdkTfm;
}
if ($args.Contains("wpf")) {
$desiredTfmValues += $WpfTfm;
}
if ($args.Contains("gtk")) {
$desiredTfmValues + $GtkTfm;
}
if ($args.Contains("macos")) {
$desiredTfmValues += $macOSTfm;
}
if ($args.Contains("ios")) {
$desiredTfmValues += $iOSTfm;
}
if ($args.Contains("droid")) {
$desiredTfmValues += $DroidTfm;
}
$targetFrameworksToRemove = $allTargetFrameworks.Where({-not $desiredTfmValues.Contains($_)})
$targetFrameworksToRemoveRegexPartial = $targetFrameworksToRemove -join "|";
$newFileContents = $fileContents -replace "<(?:$targetFrameworksToRemoveRegexPartial)>.+?>", '';
Set-Content -Force -Path .\..\Labs.TargetFrameworks.props -Value $newFileContents;

Просмотреть файл

@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Import Project="$(RepositoryDirectory)Common\Labs.TargetFrameworks.default.props" />
<Import Project="$(RepositoryDirectory)Common\Labs.TargetFrameworks.All.props" />
<PropertyGroup>
<OutputType Condition="'$(Configuration)'=='Release'">WinExe</OutputType>

Просмотреть файл

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(RepositoryDirectory)Common\Labs.SampleRefs.props" />
<Import Project="$(RepositoryDirectory)Common\Labs.TargetFrameworks.default.props" />
<Import Project="$(RepositoryDirectory)Common\Labs.TargetFrameworks.All.props" />
<Import Project="$(RepositoryDirectory)Common\Labs.Head.props" />
<PropertyGroup>