Skip to content

Gallery temp package directory survives a failed build #1256

Open

Description

@soarkit
  • Repository: microsoft/winappCli
  • Target commit: 27d8e09e77b4507b71135e8fba7858288f28354f
  • File: benchmarks/ui/setup-gallery.ps1:134-152

Summary

When the Gallery build fails, its temporary package-output directory is left behind because cleanup only runs on the success path.

Root cause

$pkgDir is created and passed as -p:AppxPackageDir before the build; a failed build throws at line 145, and the finally removes only the junction $short. The sole Remove-Item $pkgDir is after the success-path copy.

Affected code in benchmarks/ui/setup-gallery.ps1:

  126      $platformXml = "${env:ProgramFiles(x86)}\Windows Kits\10\Platforms\UAP\$($sdk.version)\Platform.xml"
  127      if (-not (Test-Path $platformXml)) { throw "Windows SDK $($sdk.version) is not installed ($platformXml). Install it with the Visual Studio Installer, or change gallery.windowsSdk in config.json to an installed SDK." }
  128  
  129      # The XAML compiler fails without a message on long paths, so build through a short junction.
  130      $short = Join-Path ([System.IO.Path]::GetTempPath()) "uibench-gallery-$PID"
  131      New-Item -ItemType Junction -Path $short -Target $src | Out-Null
  132      try {
  133          $proj = Join-Path $short 'WinUIGallery\WinUIGallery.csproj'
  134          $pkgDir = Join-Path ([System.IO.Path]::GetTempPath()) "uibench-gallery-pkg-$PID\"
  135          Remove-Item -Recurse -Force -LiteralPath (Join-Path $src 'WinUIGallery\obj'), (Join-Path $src 'WinUIGallery\bin') -ErrorAction SilentlyContinue
  136          $log = Join-Path $out 'build.log'
  137          Write-Host "Building WinUI Gallery $($config.tag) for $platform (log: $log); this takes several minutes the first time..."
  138          & dotnet build $proj -c Release -nologo -v minimal `
  139              "-p:Platform=$platform" "-p:RuntimeIdentifier=$rid" '-p:SelfContained=true' '-p:WindowsAppSDKSelfContained=true' `
  140              "-p:SamplesTargetFrameworkMoniker=net9.0-windows$($sdk.version)" "-p:WindowsSdkPackageVersion=$($sdk.packageVersion)" `
  141              '-p:GenerateAppxPackageOnBuild=true' '-p:AppxBundle=Never' '-p:UapAppxPackageBuildMode=SideloadOnly' `
  142              '-p:AppxPackageSigningEnabled=false' "-p:AppxPackageDir=$pkgDir" *> $log
  143          if ($LASTEXITCODE -ne 0) {
  144              Get-Content $log -Tail 30 | Write-Host
  145              throw "Gallery build failed (exit $LASTEXITCODE). Full log: $log"
  146          }
  147          $msix = Get-ChildItem -Path $pkgDir -Recurse -Filter *.msix | Select-Object -First 1
  148          if (-not $msix) { throw "The build produced no .msix under $pkgDir." }
  149          $cachedMsix = Join-Path $out 'WinUIGallery-uibench.msix'
  150          Copy-Item -Path $msix.FullName -Destination $cachedMsix -Force
  151          Remove-Item -Recurse -Force -LiteralPath $pkgDir -ErrorAction SilentlyContinue
  152      }
  153      finally {
  154          # Removing the junction itself, never its target.
  155          [System.IO.Directory]::Delete($short)
  156      }

Expected behavior

Temporary package-output directory is released on every Gallery build exit path.

Actual behavior

A failed Gallery build can leave its temporary package-output directory behind.

Suggested fix

Remove $pkgDir in the finally block (or add an outer trap), so both success and failure paths clean it up.

Impact

Every failed Gallery build leaves a uibench-gallery-pkg-<pid> directory with partial output in the temp folder.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions