/ .pipelines / verifyArm64Configuration.ps1
verifyArm64Configuration.ps1
 1  [CmdletBinding()]
 2  Param(
 3      [Parameter(Mandatory=$True,Position=1)]
 4      [string]$solution
 5  )
 6  
 7  Write-Output "Verifying Arm64 configuration for $solution"
 8  
 9  $errorTable = @{}
10  
11  $MSBuildLoc = & "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -prerelease -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\Microsoft.Build.dll
12  if ($null -eq $MSBuildLoc) {
13      throw "Unable to locate Microsoft.Build.dll"
14  }
15  
16  try {
17      Add-Type -Path $MSBuildLoc
18  }
19  catch {
20      # Catching because it may error on loading all the types from the assembly, but we only need one
21  }
22  
23  $solutionFile = [Microsoft.Build.Construction.SolutionFile]::Parse($solution);
24  $arm64SlnConfigs = $solutionFile.SolutionConfigurations | Where-Object {
25      $_.PlatformName -ceq "ARM64"
26  };
27  
28  # Should have two configurations. Debug and Release.
29  if($arm64SlnConfigs.Length -lt 2) {
30      Write-Host -ForegroundColor Red "Missing Solution-level Arm64 platforms"
31      exit 1;
32  }
33  
34  # List projects only.
35  $projects = $solutionFile.ProjectsInOrder | Where-Object {
36      $_.ProjectType -eq "KnownToBeMSBuildFormat" -and
37      $_.ProjectName -ne "EnvironmentVariablesUILib" -and  # UI Lib to be shipped as a nuget too, so it will be built for Any CPU
38      $_.ProjectName -ne "HostsUILib" -and                 # UI Lib to be shipped as a nuget too, so it will be built for Any CPU
39      $_.ProjectName -ne "RegistryPreviewUILib"            # UI Lib to be shipped as a nuget too, so it will be built for Any CPU
40  };
41  
42  # Enumerate through the projects and add any project with a mismatched platform and project configuration
43  foreach ($project in $projects) {
44      foreach ($slnConfig in $arm64SlnConfigs.FullName) {
45          if ($project.ProjectConfigurations.$slnConfig.FullName -cne $slnConfig) {
46              $errorTable[$project.ProjectName] += @(""`
47                  | Select-Object @{n = "Configuration"; e = { $project.ProjectConfigurations.$slnConfig.FullName ?? "Missing platform" } },
48                  @{n = "ExpectedConfiguration"; e = { $slnConfig } })
49          }
50      }
51  }
52  
53  if ($errorTable.Count -gt 0) {
54      Write-Host -ForegroundColor Red "Verification failed for the following projects:`n"
55      $errorTable.Keys | ForEach-Object {
56          Write-Host -ForegroundColor Red $_`:;
57          $errorTable[$_] | ForEach-Object {
58              Write-Host -ForegroundColor Red "$($_.ExpectedConfiguration)=$($_.Configuration)";
59          };
60          Write-Host -ForegroundColor Red `r
61      }
62      Write-Error "Found arm64 verification errors."
63      exit 1;
64  }
65  
66  Write-Output "Verification Complete"
67  exit 0;