Fixed issue where SolutionName variable could go missing. Added comments

This commit is contained in:
Arlo Godfrey 2022-04-07 14:15:04 -05:00
Родитель a52c3ec076
Коммит c597775169
3 изменённых файлов: 23 добавлений и 6 удалений

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

@ -352,4 +352,5 @@ MigrationBackup/
.ionide/
# Ignored as part of the Labs builds process
Common/Labs.TargetFrameworks.props*
Common/Labs.TargetFrameworks.props*
Common/Scripts/UpdateTargetFrameworks.CurrentVariant.*

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

@ -5,6 +5,10 @@
<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>
@ -19,4 +23,4 @@
<Exec Command="$(PowerShellCommand) -ExecutionPolicy Unrestricted -NoProfile -File $(RepositoryDirectory)Common/Scripts/UpdateTargetFrameworks.ps1 $(LabsTargetPlatformsVariant) --Verbose" WorkingDirectory="$(RepositoryDirectory)Common/Scripts/" />
</Target>
</Project>
</Project>

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

@ -1,3 +1,5 @@
# 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;
}
@ -9,6 +11,17 @@ if ($args.Length -eq 0 -or ![bool]$args[0]) {
$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
@ -20,20 +33,19 @@ if ($variant -eq "All") {
if ($variant -eq "Wasm") {
# Remove all non-wasm TFMs
$newFileContents = $fileContents -replace '<(UwpTargetFramework|WinAppSdkTargetFramework|WpfLibTargetFramework|LinuxLibTargetFramework|AndroidLibTargetFramework|MacOSLibTargetFramework|iOSLibTargetFramework)>.+?>', '';
Set-Content -Path .\..\Labs.TargetFrameworks.props.wasmonly -Value '';
}
if ($variant -eq "Windows") {
# Minimal Windows dependencies.
$newFileContents = $fileContents -replace '<(LinuxLibTargetFramework|AndroidLibTargetFramework|MacOSLibTargetFramework|iOSLibTargetFramework)>.+?>', '';
Set-Content -Path .\..\Labs.TargetFrameworks.props.windowsonly -Value '';
}
# 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;
Remove-Item -Path .\..\Labs.TargetFrameworks.props.lock;