From 538b58003b390615678afbead6f9fe29163bcf68 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Fri, 25 Jul 2025 15:38:46 +0200 Subject: [PATCH 01/16] Debugging. --- eng/build.ps1 | 64 ++++++++++ .../scripts/Test-Template.psm1 | 113 ++++++++++++++++++ 2 files changed, 177 insertions(+) diff --git a/eng/build.ps1 b/eng/build.ps1 index 854fe0679036..ca9026424d13 100644 --- a/eng/build.ps1 +++ b/eng/build.ps1 @@ -373,6 +373,50 @@ Remove-Item variable:global:_MSBuildExe -ea Ignore # Import Arcade . "$PSScriptRoot/common/tools.ps1" +# Add debugging for .NET environment after tools.ps1 import +Write-Host "=== BUILD.PS1 DOTNET ENVIRONMENT DEBUG START ===" -ForegroundColor Yellow +Write-Host "Repository root: $RepoRoot" -ForegroundColor Cyan +Write-Host "Current DOTNET_ROOT: $($env:DOTNET_ROOT)" -ForegroundColor Cyan +Write-Host "Current DOTNET_ROOT_X86: $($env:DOTNET_ROOT_X86)" -ForegroundColor Cyan +Write-Host "Current DOTNET_MULTILEVEL_LOOKUP: $($env:DOTNET_MULTILEVEL_LOOKUP)" -ForegroundColor Cyan +Write-Host "Current PATH (first 300 chars): $($env:PATH.Substring(0, [Math]::Min(300, $env:PATH.Length)))" -ForegroundColor Cyan + +# Check what Get-Command dotnet finds after tools.ps1 +$buildDotnetCommand = Get-Command dotnet -ErrorAction SilentlyContinue +if ($buildDotnetCommand) { + Write-Host "Get-Command dotnet found: $($buildDotnetCommand.Source)" -ForegroundColor Cyan + Write-Host "Build dotnet version:" -ForegroundColor Cyan + & $buildDotnetCommand.Source --version | ForEach-Object { Write-Host " $_" -ForegroundColor Cyan } + Write-Host "Build dotnet --info:" -ForegroundColor Cyan + & $buildDotnetCommand.Source --info | ForEach-Object { Write-Host " $_" -ForegroundColor Cyan } +} else { + Write-Host "Get-Command dotnet found: NONE" -ForegroundColor Red +} + +# Check repository .dotnet folder +$repoDotnetPath = "$RepoRoot\.dotnet" +Write-Host "Repository .dotnet path: $repoDotnetPath" -ForegroundColor Cyan +Write-Host "Repository .dotnet exists: $(Test-Path $repoDotnetPath)" -ForegroundColor Cyan +if (Test-Path $repoDotnetPath) { + Write-Host "Repository .dotnet contents:" -ForegroundColor Cyan + Get-ChildItem $repoDotnetPath -ErrorAction SilentlyContinue | ForEach-Object { Write-Host " $($_.Name)" -ForegroundColor Cyan } + + $repoDotnetExe = "$repoDotnetPath\dotnet.exe" + if (Test-Path $repoDotnetExe) { + Write-Host "Repository dotnet version:" -ForegroundColor Cyan + & $repoDotnetExe --version | ForEach-Object { Write-Host " $_" -ForegroundColor Cyan } + } +} + +# Check global.json +$globalJsonPath = "$RepoRoot\global.json" +if (Test-Path $globalJsonPath) { + Write-Host "global.json content:" -ForegroundColor Cyan + Get-Content $globalJsonPath | ForEach-Object { Write-Host " $_" -ForegroundColor Cyan } +} + +Write-Host "=== BUILD.PS1 DOTNET ENVIRONMENT DEBUG END ===" -ForegroundColor Yellow + function LocateJava { $foundJdk = $false $javac = Get-Command javac -ErrorAction Ignore -CommandType Application @@ -501,6 +545,8 @@ try { if (-not $OnlyBuildRepoTasks) { if ($performDesktopBuild) { Write-Host + Write-Host "=== PERFORMING DESKTOP BUILD ===" -ForegroundColor Yellow + Write-Host "MSBuild engine: vs (desktop)" -ForegroundColor Cyan Remove-Item variable:global:_BuildTool -ErrorAction Ignore $msbuildEngine = 'vs' @@ -509,14 +555,32 @@ try { $MSBuildOnlyArguments += $dotnetBuildArguments } + Write-Host "MSBuild arguments: @MSBuildArguments @MSBuildOnlyArguments" -ForegroundColor Cyan + Write-Host "About to run desktop MSBuild - checking environment:" -ForegroundColor Cyan + $currentDotnet = Get-Command dotnet -ErrorAction SilentlyContinue + if ($currentDotnet) { + Write-Host "Current dotnet: $($currentDotnet.Source)" -ForegroundColor Cyan + & $currentDotnet.Source --version | ForEach-Object { Write-Host " Version: $_" -ForegroundColor Cyan } + } + MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments @MSBuildOnlyArguments } if ($performDotnetBuild) { Write-Host + Write-Host "=== PERFORMING DOTNET BUILD ===" -ForegroundColor Yellow + Write-Host "MSBuild engine: dotnet" -ForegroundColor Cyan Remove-Item variable:global:_BuildTool -ErrorAction Ignore $msbuildEngine = 'dotnet' + Write-Host "MSBuild arguments: @MSBuildArguments @dotnetBuildArguments" -ForegroundColor Cyan + Write-Host "About to run dotnet MSBuild - checking environment:" -ForegroundColor Cyan + $currentDotnet = Get-Command dotnet -ErrorAction SilentlyContinue + if ($currentDotnet) { + Write-Host "Current dotnet: $($currentDotnet.Source)" -ForegroundColor Cyan + & $currentDotnet.Source --version | ForEach-Object { Write-Host " Version: $_" -ForegroundColor Cyan } + } + MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments @dotnetBuildArguments } } diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 9f63b5201cae..0a37d00849c6 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -18,28 +18,129 @@ function Test-Template { [string] $TargetFramework = "net10.0" ) + Write-Verbose "=== DOTNET ENVIRONMENT DEBUG START ===" + Write-Verbose "PSScriptRoot: $PSScriptRoot" + Write-Verbose "Current DOTNET_ROOT: $($env:DOTNET_ROOT)" + Write-Verbose "Current DOTNET_ROOT_X86: $($env:DOTNET_ROOT_X86)" + Write-Verbose "Current PATH: $($env:PATH)" + + # Check what Get-Command dotnet finds + $dotnetCommand = Get-Command dotnet -ErrorAction SilentlyContinue + if ($dotnetCommand) { + Write-Verbose "Get-Command dotnet found: $($dotnetCommand.Source)" + Write-Verbose "Dotnet version from Get-Command location:" + & $dotnetCommand.Source --version | ForEach-Object { Write-Verbose " $_" } + } else { + Write-Verbose "Get-Command dotnet found: NONE" + } + if(-not (Test-Path "$PSScriptRoot/.dotnet")){ + Write-Verbose "Local .dotnet folder does not exist, creating it..." + + # Original logic: use Get-Command dotnet $dotnetFolder = Get-Command dotnet | Select-Object -ExpandProperty Source | Split-Path -Parent; + Write-Verbose "Dotnet folder from Get-Command: $dotnetFolder" + + # Let's also check what's in the repo root + $repoRoot = "$PSScriptRoot/../../../"; + $repoDotnetFolder = "$repoRoot/.dotnet"; + Write-Verbose "Repository root: $repoRoot" + Write-Verbose "Repository .dotnet folder: $repoDotnetFolder" + Write-Verbose "Repository .dotnet exists: $(Test-Path $repoDotnetFolder)" + + if (Test-Path $repoDotnetFolder) { + Write-Verbose "Repository .dotnet contents:" + Get-ChildItem $repoDotnetFolder -ErrorAction SilentlyContinue | ForEach-Object { Write-Verbose " $($_.Name)" } + + # Check version in repo dotnet + $repoDotnetExe = "$repoDotnetFolder/dotnet.exe" + if (Test-Path $repoDotnetExe) { + Write-Verbose "Repository dotnet version:" + & $repoDotnetExe --version | ForEach-Object { Write-Verbose " $_" } + } + } + Write-Verbose "Copying dotnet folder from $dotnetFolder to $PSScriptRoot/.dotnet"; Copy-Item -Path $dotnetFolder -Destination "$PSScriptRoot/.dotnet" -Recurse; + + Write-Verbose "Copy completed. Verifying local .dotnet folder..." + if (Test-Path "$PSScriptRoot/.dotnet") { + Write-Verbose "Local .dotnet folder created successfully" + $localDotnetExe = "$PSScriptRoot/.dotnet/dotnet.exe" + if (Test-Path $localDotnetExe) { + Write-Verbose "Local dotnet version after copy:" + & $localDotnetExe --version | ForEach-Object { Write-Verbose " $_" } + } + } else { + Write-Verbose "ERROR: Local .dotnet folder was not created!" + } + } else { + Write-Verbose "Local .dotnet folder already exists" + $localDotnetExe = "$PSScriptRoot/.dotnet/dotnet.exe" + if (Test-Path $localDotnetExe) { + Write-Verbose "Existing local dotnet version:" + & $localDotnetExe --version | ForEach-Object { Write-Verbose " $_" } + } } Write-Verbose "Patching Microsoft.AspNetCore.App"; $builtRuntime = Resolve-Path "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/aspnetcore-runtime-*-dev-win-x64.zip" | Where-Object { $_ -match "aspnetcore-runtime-[0-9.]+-dev-win-x64.zip" }; + Write-Verbose "Built runtime package: $builtRuntime"; Write-Verbose "Patching Microsoft.AspNetCore.App from $builtRuntime"; Remove-Item "$PSScriptRoot/.runtime" -Recurse -ErrorAction Ignore; Expand-Archive -Path $builtRuntime -DestinationPath "$PSScriptRoot/.runtime" -Force; + + Write-Verbose "Extracted runtime contents:"; + if (Test-Path "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App") { + Get-ChildItem "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" } + } + + Write-Verbose "Removing existing dev runtimes from local .dotnet..."; Remove-Item "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/*-dev" -Recurse -ErrorAction Ignore; + + Write-Verbose "Before patching - local .dotnet ASP.NET Core runtimes:"; + if (Test-Path "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App") { + Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" } + } + Write-Verbose "Copying $PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App to $PSScriptRoot/.dotnet/shared"; Copy-Item -Path "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" -Destination "$PSScriptRoot/.dotnet/shared" -Recurse -Force; + Write-Verbose "After patching - local .dotnet ASP.NET Core runtimes:"; + if (Test-Path "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App") { + Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" } + } + + Write-Verbose "=== SETTING UP ENVIRONMENT ===" + Write-Verbose "Setting DOTNET_ROOT to: $PSScriptRoot/.dotnet" $env:DOTNET_ROOT = "$PSScriptRoot/.dotnet"; + Write-Verbose "Setting DOTNET_ROOT_X86 to: $PSScriptRoot/.dotnet" $env:DOTNET_ROOT_X86 = "$PSScriptRoot/.dotnet"; + Write-Verbose "Prepending to PATH: $PSScriptRoot/.dotnet" $env:Path = "$PSScriptRoot/.dotnet;$env:Path"; + + Write-Verbose "Final environment variables:" + Write-Verbose " DOTNET_ROOT: $($env:DOTNET_ROOT)" + Write-Verbose " DOTNET_ROOT_X86: $($env:DOTNET_ROOT_X86)" + Write-Verbose " PATH (first 200 chars): $($env:PATH.Substring(0, [Math]::Min(200, $env:PATH.Length)))" + + # Verify which dotnet we'll use after env changes + $finalDotnetCommand = Get-Command dotnet -ErrorAction SilentlyContinue + if ($finalDotnetCommand) { + Write-Verbose "After env setup, Get-Command dotnet finds: $($finalDotnetCommand.Source)" + Write-Verbose "Final dotnet version:" + & $finalDotnetCommand.Source --version | ForEach-Object { Write-Verbose " $_" } + Write-Verbose "Final dotnet --info:" + & $finalDotnetCommand.Source --info | ForEach-Object { Write-Verbose " $_" } + } + Write-Verbose "=== DOTNET ENVIRONMENT DEBUG END ===" $tmpDir = "$PSScriptRoot/$templateName"; + Write-Verbose "Template working directory: $tmpDir" Remove-Item -Path $tmpDir -Recurse -ErrorAction Ignore; + Write-Verbose "Running dotnet pack to build template packages..." Push-Location ..; try { + Write-Verbose "Current location for dotnet pack: $(Get-Location)" dotnet pack } finally { @@ -47,8 +148,10 @@ function Test-Template { } $PackagePath = Resolve-Path "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/$TemplatePackagePath"; + Write-Verbose "Template package path: $PackagePath" $PackageName = (Get-Item $PackagePath).Name; + Write-Verbose "Template package name: $PackageName" if (-not (Test-Path "$($env:USERPROFILE)/.templateengine/packages/$PackageName")) { Write-Verbose "Installing package from $PackagePath"; @@ -75,8 +178,15 @@ function Test-Template { try { $TemplateArguments = , "new" + $TemplateArguments + , "--no-restore"; Write-Verbose "Running dotnet command with arguments: $TemplateArguments"; + Write-Verbose "Current working directory: $(Get-Location)" + Write-Verbose "About to run dotnet new - checking dotnet version one more time:" + dotnet --version | ForEach-Object { Write-Verbose " $_" } + dotnet @TemplateArguments; + Write-Verbose "Template creation completed. Checking created files:" + Get-ChildItem . -Recurse -File | Select-Object -First 10 | ForEach-Object { Write-Verbose " $($_.FullName)" } + $proj = Get-ChildItem $tmpDir -Recurse -File -Filter '*.csproj' -Depth 3; if ($proj.Length -eq 0) { $proj = Get-ChildItem $tmpDir -Recurse -File -Filter '*.fsproj' -Depth 3; @@ -119,6 +229,9 @@ function Test-Template { } $publishOutputDir = "./.publish"; + Write-Verbose "Publishing template to: $publishOutputDir" + Write-Verbose "About to run dotnet publish - final dotnet version check:" + dotnet --version | ForEach-Object { Write-Verbose " $_" } Write-Verbose "Running dotnet publish --configuration $Configuration --output $publishOutputDir"; dotnet.exe publish --configuration $Configuration --output $publishOutputDir; } From a1939c12fbdc918b5073f2484c73143f7b4b06b3 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Fri, 25 Jul 2025 17:35:19 +0200 Subject: [PATCH 02/16] Make the CI fail with rename error. --- .../content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.Main.cs | 1 + .../content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.Main.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.Main.cs index be71c6ad04dd..1b8771773c04 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.Main.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.Main.cs @@ -107,6 +107,7 @@ public static void Main(string[] args) #endif } + app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); #if (HasHttpsProfile) app.UseHttpsRedirection(); diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.cs index c325a1f788a6..23924798a9fc 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.cs @@ -100,6 +100,7 @@ app.UseHsts(); #endif } +app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); #if (HasHttpsProfile) app.UseHttpsRedirection(); From 03d35ca312c880336e74be8069052ad993a6a545 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Fri, 25 Jul 2025 18:31:06 +0200 Subject: [PATCH 03/16] Verify patching. --- .../scripts/Test-Template.psm1 | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 0a37d00849c6..9c0ac48ac611 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -96,7 +96,20 @@ function Test-Template { } Write-Verbose "Removing existing dev runtimes from local .dotnet..."; - Remove-Item "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/*-dev" -Recurse -ErrorAction Ignore; + try { + $devRuntimes = Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/*-dev" -ErrorAction SilentlyContinue; + if ($devRuntimes) { + Write-Verbose "Found existing dev runtimes to remove: $($devRuntimes.Name -join ', ')"; + Remove-Item "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/*-dev" -Recurse -Force -ErrorAction Stop; + Write-Verbose "Successfully removed existing dev runtimes"; + } else { + Write-Verbose "No existing dev runtimes found to remove"; + } + } + catch { + Write-Warning "Failed to remove existing dev runtimes: $($_.Exception.Message)"; + # Continue anyway - this might not be critical + } Write-Verbose "Before patching - local .dotnet ASP.NET Core runtimes:"; if (Test-Path "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App") { @@ -104,13 +117,35 @@ function Test-Template { } Write-Verbose "Copying $PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App to $PSScriptRoot/.dotnet/shared"; - Copy-Item -Path "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" -Destination "$PSScriptRoot/.dotnet/shared" -Recurse -Force; + try { + Copy-Item -Path "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" -Destination "$PSScriptRoot/.dotnet/shared" -Recurse -Force -ErrorAction Stop; + Write-Verbose "Runtime copy completed successfully"; + } + catch { + Write-Error "Failed to copy runtime: $($_.Exception.Message)"; + throw; + } Write-Verbose "After patching - local .dotnet ASP.NET Core runtimes:"; if (Test-Path "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App") { Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" } } + # Verify critical files were patched correctly + Write-Verbose "Verifying patched runtime files..."; + $devRuntimePath = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev"; + if (Test-Path $devRuntimePath) { + $diagnosticsDll = "$devRuntimePath/Microsoft.AspNetCore.Diagnostics.dll"; + if (Test-Path $diagnosticsDll) { + $fileInfo = Get-Item $diagnosticsDll; + Write-Verbose "Microsoft.AspNetCore.Diagnostics.dll found - Size: $($fileInfo.Length) bytes, Modified: $($fileInfo.LastWriteTime)"; + } else { + Write-Warning "Microsoft.AspNetCore.Diagnostics.dll not found in patched runtime!"; + } + } else { + Write-Warning "Dev runtime folder not found at $devRuntimePath"; + } + Write-Verbose "=== SETTING UP ENVIRONMENT ===" Write-Verbose "Setting DOTNET_ROOT to: $PSScriptRoot/.dotnet" $env:DOTNET_ROOT = "$PSScriptRoot/.dotnet"; From 562a30616e91dfcb1c0d8e8d59be43af8e558a2c Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 08:46:03 +0200 Subject: [PATCH 04/16] Force reload module for debugging + do not run dotnet pack when previous CI commands already packed into shipping artifacts. --- .../scripts/Run-BlazorWeb-Locally.ps1 | 2 +- .../scripts/Test-Template.psm1 | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/ProjectTemplates/scripts/Run-BlazorWeb-Locally.ps1 b/src/ProjectTemplates/scripts/Run-BlazorWeb-Locally.ps1 index fe5b35826f06..96919e3e60a7 100644 --- a/src/ProjectTemplates/scripts/Run-BlazorWeb-Locally.ps1 +++ b/src/ProjectTemplates/scripts/Run-BlazorWeb-Locally.ps1 @@ -78,7 +78,7 @@ $templateArguments += "--use-program-main" } - Import-Module -Name "$PSScriptRoot/Test-Template.psm1"; + Import-Module -Name "$PSScriptRoot/Test-Template.psm1" -Force; Test-Template ` -TemplateName "MyBlazorApp" ` diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 9c0ac48ac611..8be5590591c5 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -172,17 +172,18 @@ function Test-Template { $tmpDir = "$PSScriptRoot/$templateName"; Write-Verbose "Template working directory: $tmpDir" Remove-Item -Path $tmpDir -Recurse -ErrorAction Ignore; - Write-Verbose "Running dotnet pack to build template packages..." - Push-Location ..; - try { - Write-Verbose "Current location for dotnet pack: $(Get-Location)" - dotnet pack - } - finally { - Pop-Location; + + # Check if template packages exist (should be built by main CI build process) + $PackagePathPattern = "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/$TemplatePackagePath" + Write-Verbose "Looking for template packages at: $PackagePathPattern" + + $PackagePath = Get-ChildItem -Path "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/" -Filter $TemplatePackagePath -ErrorAction SilentlyContinue | Select-Object -First 1 + if (-not $PackagePath) { + Write-Error "Template packages not found at $PackagePathPattern. Ensure the main build has completed with -pack option before running template tests." + return } - $PackagePath = Resolve-Path "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/$TemplatePackagePath"; + $PackagePath = $PackagePath.FullName Write-Verbose "Template package path: $PackagePath" $PackageName = (Get-Item $PackagePath).Name; From a68062178f74690767718e2ea31c108bafe20f2f Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 09:01:35 +0200 Subject: [PATCH 05/16] Make sure the old packs are gone before we start patching. --- .../scripts/Test-Template.psm1 | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 8be5590591c5..6a8bfc52b9f6 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -95,19 +95,31 @@ function Test-Template { Get-ChildItem "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" } } - Write-Verbose "Removing existing dev runtimes from local .dotnet..."; + Write-Verbose "Removing ALL existing ASP.NET Core runtimes from local .dotnet..."; try { - $devRuntimes = Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/*-dev" -ErrorAction SilentlyContinue; - if ($devRuntimes) { - Write-Verbose "Found existing dev runtimes to remove: $($devRuntimes.Name -join ', ')"; - Remove-Item "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/*-dev" -Recurse -Force -ErrorAction Stop; - Write-Verbose "Successfully removed existing dev runtimes"; + $aspNetCoreRuntimePath = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App"; + if (Test-Path $aspNetCoreRuntimePath) { + $existingRuntimes = Get-ChildItem $aspNetCoreRuntimePath -ErrorAction SilentlyContinue; + if ($existingRuntimes) { + Write-Verbose "Found existing ASP.NET Core runtimes to remove: $($existingRuntimes.Name -join ', ')"; + Remove-Item $aspNetCoreRuntimePath -Recurse -Force -ErrorAction Stop; + Write-Verbose "Successfully removed all existing ASP.NET Core runtimes"; + + # Recreate the directory + New-Item -Path $aspNetCoreRuntimePath -ItemType Directory -Force | Out-Null; + Write-Verbose "Recreated ASP.NET Core runtime directory"; + } else { + Write-Verbose "No existing ASP.NET Core runtimes found to remove"; + } } else { - Write-Verbose "No existing dev runtimes found to remove"; + Write-Verbose "ASP.NET Core runtime directory does not exist"; + # Create the directory + New-Item -Path $aspNetCoreRuntimePath -ItemType Directory -Force | Out-Null; + Write-Verbose "Created ASP.NET Core runtime directory"; } } catch { - Write-Warning "Failed to remove existing dev runtimes: $($_.Exception.Message)"; + Write-Warning "Failed to remove existing ASP.NET Core runtimes: $($_.Exception.Message)"; # Continue anyway - this might not be critical } From f730fef7e53623da86463cf6d30b4640f49ff0ac Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 09:29:21 +0200 Subject: [PATCH 06/16] More size checks. --- .../scripts/Test-Template.psm1 | 52 ++++++++++++++++--- 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 6a8bfc52b9f6..3a086ff061c2 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -4,6 +4,22 @@ Set-StrictMode -Version 2 $ErrorActionPreference = 'Stop' +function Check-DiagnosticsDll { + param( + [string]$Path, + [string]$Description + ) + + if (Test-Path $Path) { + $fileInfo = Get-Item $Path; + Write-Verbose "[dll check] $Description - found - Size: $($fileInfo.Length) bytes, Modified: $($fileInfo.LastWriteTime)"; + return $true; + } else { + Write-Verbose "[dll check] $Description - not found at $Path"; + return $false; + } +} + function Test-Template { [CmdletBinding()] param ( @@ -84,8 +100,27 @@ function Test-Template { } Write-Verbose "Patching Microsoft.AspNetCore.App"; + + # [dll check] 1) Check Microsoft.AspNetCore.Diagnostics.dll in PSScriptRoot before patching + $psScriptDiagnosticsDll = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev/Microsoft.AspNetCore.Diagnostics.dll"; + Check-DiagnosticsDll -Path $psScriptDiagnosticsDll -Description "1) PSScriptRoot Microsoft.AspNetCore.Diagnostics.dll before patching"; + $builtRuntime = Resolve-Path "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/aspnetcore-runtime-*-dev-win-x64.zip" | Where-Object { $_ -match "aspnetcore-runtime-[0-9.]+-dev-win-x64.zip" }; Write-Verbose "Built runtime package: $builtRuntime"; + + # [dll check] 3) Check Microsoft.AspNetCore.Diagnostics.dll in artifacts + $artifactsDiagnosticsDll = "$PSScriptRoot/../../../artifacts/bin/Microsoft.AspNetCore.Diagnostics/$Configuration/$TargetFramework/Microsoft.AspNetCore.Diagnostics.dll"; + if (-not (Check-DiagnosticsDll -Path $artifactsDiagnosticsDll -Description "3) Artifacts Microsoft.AspNetCore.Diagnostics.dll")) { + # Try alternative location + $artifactsDiagnosticsDll2 = "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/Microsoft.AspNetCore.Diagnostics.$TargetFramework.*.nupkg"; + $artifactsNupkg = Get-ChildItem $artifactsDiagnosticsDll2 -ErrorAction SilentlyContinue | Select-Object -First 1; + if ($artifactsNupkg) { + Write-Verbose "[dll check] Found Microsoft.AspNetCore.Diagnostics nupkg: $($artifactsNupkg.FullName)"; + } else { + Write-Verbose "[dll check] No Microsoft.AspNetCore.Diagnostics nupkg found in artifacts"; + } + } + Write-Verbose "Patching Microsoft.AspNetCore.App from $builtRuntime"; Remove-Item "$PSScriptRoot/.runtime" -Recurse -ErrorAction Ignore; Expand-Archive -Path $builtRuntime -DestinationPath "$PSScriptRoot/.runtime" -Force; @@ -95,6 +130,12 @@ function Test-Template { Get-ChildItem "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" } } + # [dll check] 2) Check Microsoft.AspNetCore.Diagnostics.dll in unpacked zip contents + $unpackedDiagnosticsDll = "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App/10.0.0-dev/Microsoft.AspNetCore.Diagnostics.dll"; + if (-not (Check-DiagnosticsDll -Path $unpackedDiagnosticsDll -Description "2) Unpacked Microsoft.AspNetCore.Diagnostics.dll")) { + Write-Warning "[dll check] Critical: Unpacked Microsoft.AspNetCore.Diagnostics.dll not found!"; + } + Write-Verbose "Removing ALL existing ASP.NET Core runtimes from local .dotnet..."; try { $aspNetCoreRuntimePath = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App"; @@ -145,17 +186,16 @@ function Test-Template { # Verify critical files were patched correctly Write-Verbose "Verifying patched runtime files..."; + + # [dll check] 4) Check Microsoft.AspNetCore.Diagnostics.dll after patching (existing check) $devRuntimePath = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev"; if (Test-Path $devRuntimePath) { $diagnosticsDll = "$devRuntimePath/Microsoft.AspNetCore.Diagnostics.dll"; - if (Test-Path $diagnosticsDll) { - $fileInfo = Get-Item $diagnosticsDll; - Write-Verbose "Microsoft.AspNetCore.Diagnostics.dll found - Size: $($fileInfo.Length) bytes, Modified: $($fileInfo.LastWriteTime)"; - } else { - Write-Warning "Microsoft.AspNetCore.Diagnostics.dll not found in patched runtime!"; + if (-not (Check-DiagnosticsDll -Path $diagnosticsDll -Description "4) Microsoft.AspNetCore.Diagnostics.dll after patching")) { + Write-Warning "[dll check] Critical: Microsoft.AspNetCore.Diagnostics.dll not found in patched runtime!"; } } else { - Write-Warning "Dev runtime folder not found at $devRuntimePath"; + Write-Warning "[dll check] Dev runtime folder not found at $devRuntimePath"; } Write-Verbose "=== SETTING UP ENVIRONMENT ===" From 731aa59f1e6570b3de5cc613c3f1252a993c3be4 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 10:29:31 +0200 Subject: [PATCH 07/16] Upload artifacts: shared before and after patching and the shipping zip. --- .../scripts/Test-Template.psm1 | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 3a086ff061c2..171386f60e14 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -122,6 +122,13 @@ function Test-Template { } Write-Verbose "Patching Microsoft.AspNetCore.App from $builtRuntime"; + + # Upload the runtime zip to CI artifacts for analysis + if (Test-Path $builtRuntime) { + Write-Verbose "Uploading runtime zip to CI artifacts"; + Write-Host "##vso[artifact.upload containerfolder=runtime-zip;artifactname=runtime-zip]$builtRuntime"; + } + Remove-Item "$PSScriptRoot/.runtime" -Recurse -ErrorAction Ignore; Expand-Archive -Path $builtRuntime -DestinationPath "$PSScriptRoot/.runtime" -Force; @@ -169,6 +176,13 @@ function Test-Template { Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" } } + # Upload shared directory BEFORE patching to CI artifacts + if (Test-Path "$PSScriptRoot/.dotnet/shared") { + $beforeSharedPath = "$PSScriptRoot/.dotnet/shared"; + Write-Verbose "Uploading shared directory BEFORE patching to CI artifacts"; + Write-Host "##vso[artifact.upload containerfolder=shared-before;artifactname=shared-before]$beforeSharedPath"; + } + Write-Verbose "Copying $PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App to $PSScriptRoot/.dotnet/shared"; try { Copy-Item -Path "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" -Destination "$PSScriptRoot/.dotnet/shared" -Recurse -Force -ErrorAction Stop; @@ -184,6 +198,13 @@ function Test-Template { Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" } } + # Upload shared directory AFTER patching to CI artifacts + if (Test-Path "$PSScriptRoot/.dotnet/shared") { + $afterSharedPath = "$PSScriptRoot/.dotnet/shared"; + Write-Verbose "Uploading shared directory AFTER patching to CI artifacts"; + Write-Host "##vso[artifact.upload containerfolder=shared-after;artifactname=shared-after]$afterSharedPath"; + } + # Verify critical files were patched correctly Write-Verbose "Verifying patched runtime files..."; From 2611b48ee141ae978bab9f7fa1eec74be9cd5002 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 12:14:53 +0200 Subject: [PATCH 08/16] Upload publish binlog - make sure publish uses the dlls we expect it to. --- src/ProjectTemplates/scripts/Test-Template.psm1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 171386f60e14..1c890225fba2 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -338,11 +338,21 @@ function Test-Template { } $publishOutputDir = "./.publish"; + $publishBinlogPath = "./publish.binlog"; Write-Verbose "Publishing template to: $publishOutputDir" Write-Verbose "About to run dotnet publish - final dotnet version check:" dotnet --version | ForEach-Object { Write-Verbose " $_" } - Write-Verbose "Running dotnet publish --configuration $Configuration --output $publishOutputDir"; - dotnet.exe publish --configuration $Configuration --output $publishOutputDir; + Write-Verbose "Running dotnet publish --configuration $Configuration --output $publishOutputDir with binary log"; + dotnet.exe publish --configuration $Configuration --output $publishOutputDir -bl:$publishBinlogPath; + + # Upload the publish binlog to CI artifacts for analysis + if (Test-Path $publishBinlogPath) { + $fullBinlogPath = Resolve-Path $publishBinlogPath; + Write-Verbose "Uploading publish binlog to CI artifacts: $fullBinlogPath"; + Write-Host "##vso[artifact.upload containerfolder=publish-binlog;artifactname=publish-binlog]$fullBinlogPath"; + } else { + Write-Warning "Publish binlog not found at $publishBinlogPath"; + } } finally { Pop-Location -StackName TemplateFolder; From b35f0c879aeb90af56a6d457039183f1edb0bb8a Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 13:33:04 +0200 Subject: [PATCH 09/16] Patch packs, so that they are same as shared. --- .../scripts/Test-Template.psm1 | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 1c890225fba2..36e9bacedde1 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -219,6 +219,65 @@ function Test-Template { Write-Warning "[dll check] Dev runtime folder not found at $devRuntimePath"; } + # ===== PATCH REFERENCE ASSEMBLIES ===== + Write-Verbose "=== PATCHING REFERENCE ASSEMBLIES ==="; + + # Find the reference pack directory + $packsDir = "$PSScriptRoot/.dotnet/packs/Microsoft.AspNetCore.App.Ref"; + if (Test-Path $packsDir) { + Write-Verbose "Found reference packs directory: $packsDir"; + + # List existing reference pack versions + $existingRefPacks = Get-ChildItem $packsDir -ErrorAction SilentlyContinue; + if ($existingRefPacks) { + Write-Verbose "Existing reference pack versions: $($existingRefPacks.Name -join ', ')"; + + # Check if dev version of reference assemblies exist in the runtime zip + $devRefAssembliesSource = "$PSScriptRoot/.runtime/ref/Microsoft.AspNetCore.App"; + if (Test-Path $devRefAssembliesSource) { + Write-Verbose "Found dev reference assemblies in runtime zip at: $devRefAssembliesSource"; + + # Create dev version reference pack directory + $devRefPackDir = "$packsDir/10.0.0-dev"; + New-Item -Path $devRefPackDir -ItemType Directory -Force | Out-Null; + + # Copy reference assemblies structure + Write-Verbose "Copying dev reference assemblies to: $devRefPackDir"; + Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force; + + Write-Verbose "Successfully created dev reference pack at $devRefPackDir"; + + # [dll check] 5) Check reference assembly + $devRefDiagnosticsDll = "$devRefPackDir/ref/net10.0/Microsoft.AspNetCore.Diagnostics.dll"; + Check-DiagnosticsDll -Path $devRefDiagnosticsDll -Description "5) Dev reference Microsoft.AspNetCore.Diagnostics.dll"; + } else { + Write-Warning "No dev reference assemblies found in runtime zip - reference assemblies not patched!"; + + # Alternative: try to copy from the latest preview version and replace specific DLLs + $latestRefPack = $existingRefPacks | Sort-Object Name -Descending | Select-Object -First 1; + if ($latestRefPack) { + Write-Verbose "Attempting to create dev reference pack based on: $($latestRefPack.Name)"; + $devRefPackDir = "$packsDir/10.0.0-dev"; + + # Copy the latest reference pack as base + Copy-Item -Path $latestRefPack.FullName -Destination $devRefPackDir -Recurse -Force; + + # Replace specific reference DLLs with runtime DLLs (not ideal but might work) + $runtimeDiagnosticsDll = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev/Microsoft.AspNetCore.Diagnostics.dll"; + $refDiagnosticsDll = "$devRefPackDir/ref/net10.0/Microsoft.AspNetCore.Diagnostics.dll"; + + if ((Test-Path $runtimeDiagnosticsDll) -and (Test-Path (Split-Path $refDiagnosticsDll))) { + Copy-Item -Path $runtimeDiagnosticsDll -Destination $refDiagnosticsDll -Force; + Write-Verbose "Replaced reference Microsoft.AspNetCore.Diagnostics.dll with runtime version"; + Check-DiagnosticsDll -Path $refDiagnosticsDll -Description "5) Patched reference Microsoft.AspNetCore.Diagnostics.dll"; + } + } + } + } + } else { + Write-Warning "Reference packs directory not found at $packsDir"; + } + Write-Verbose "=== SETTING UP ENVIRONMENT ===" Write-Verbose "Setting DOTNET_ROOT to: $PSScriptRoot/.dotnet" $env:DOTNET_ROOT = "$PSScriptRoot/.dotnet"; From ac7f4367afbba5195b34ced3a8ba8b0243105b14 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 15:32:26 +0200 Subject: [PATCH 10/16] Remove contents of packs before patching it + upload to artifacts --- .../scripts/Test-Template.psm1 | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 36e9bacedde1..515e080c16f3 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -105,12 +105,24 @@ function Test-Template { $psScriptDiagnosticsDll = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev/Microsoft.AspNetCore.Diagnostics.dll"; Check-DiagnosticsDll -Path $psScriptDiagnosticsDll -Description "1) PSScriptRoot Microsoft.AspNetCore.Diagnostics.dll before patching"; - $builtRuntime = Resolve-Path "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/aspnetcore-runtime-*-dev-win-x64.zip" | Where-Object { $_ -match "aspnetcore-runtime-[0-9.]+-dev-win-x64.zip" }; - Write-Verbose "Built runtime package: $builtRuntime"; - - # [dll check] 3) Check Microsoft.AspNetCore.Diagnostics.dll in artifacts - $artifactsDiagnosticsDll = "$PSScriptRoot/../../../artifacts/bin/Microsoft.AspNetCore.Diagnostics/$Configuration/$TargetFramework/Microsoft.AspNetCore.Diagnostics.dll"; - if (-not (Check-DiagnosticsDll -Path $artifactsDiagnosticsDll -Description "3) Artifacts Microsoft.AspNetCore.Diagnostics.dll")) { + # Remove all existing subdirectories (old versions) + Get-ChildItem $packsDir -Directory | Remove-Item -Recurse -Force -ErrorAction Ignore; + Write-Verbose "Removed all existing reference pack versions from: $packsDir"; + + # Check if dev version of reference assemblies exist in the runtime zip + $devRefAssembliesSource = "$PSScriptRoot/.runtime/ref/Microsoft.AspNetCore.App"; + if (Test-Path $devRefAssembliesSource) { + Write-Verbose "Found dev reference assemblies in runtime zip at: $devRefAssembliesSource"; + $devRefPackDir = "$packsDir/10.0.0-dev"; + # Remove any existing dev reference pack directory first + if (Test-Path $devRefPackDir) { + Remove-Item -Path $devRefPackDir -Recurse -Force -ErrorAction Ignore; + } + New-Item -Path $devRefPackDir -ItemType Directory -Force | Out-Null; + # Copy the entire structure from the dev ref assemblies source + Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force; + Write-Verbose "Successfully copied dev reference assemblies to $devRefPackDir"; + } # Try alternative location $artifactsDiagnosticsDll2 = "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/Microsoft.AspNetCore.Diagnostics.$TargetFramework.*.nupkg"; $artifactsNupkg = Get-ChildItem $artifactsDiagnosticsDll2 -ErrorAction SilentlyContinue | Select-Object -First 1; @@ -250,6 +262,13 @@ function Test-Template { # [dll check] 5) Check reference assembly $devRefDiagnosticsDll = "$devRefPackDir/ref/net10.0/Microsoft.AspNetCore.Diagnostics.dll"; Check-DiagnosticsDll -Path $devRefDiagnosticsDll -Description "5) Dev reference Microsoft.AspNetCore.Diagnostics.dll"; + + # Upload the packs directory to CI artifacts for analysis + if (Test-Path "$PSScriptRoot/.dotnet/packs") { + $packsUploadPath = "$PSScriptRoot/.dotnet/packs"; + Write-Verbose "Uploading packs directory to CI artifacts: $packsUploadPath"; + Write-Host "##vso[artifact.upload containerfolder=packs-after;artifactname=packs-after]$packsUploadPath"; + } } else { Write-Warning "No dev reference assemblies found in runtime zip - reference assemblies not patched!"; From 43c74349cae7cab0b9f9c8fa5a05b5de8135884c Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 16:46:04 +0200 Subject: [PATCH 11/16] Syntax... --- .../scripts/Test-Template.psm1 | 84 +++++++++++-------- 1 file changed, 47 insertions(+), 37 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 515e080c16f3..34c92037f24e 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -232,69 +232,79 @@ function Test-Template { } # ===== PATCH REFERENCE ASSEMBLIES ===== - Write-Verbose "=== PATCHING REFERENCE ASSEMBLIES ==="; + Write-Verbose "=== PATCHING REFERENCE ASSEMBLIES ===" # Find the reference pack directory - $packsDir = "$PSScriptRoot/.dotnet/packs/Microsoft.AspNetCore.App.Ref"; - if (Test-Path $packsDir) { - Write-Verbose "Found reference packs directory: $packsDir"; + $packsDir = "$PSScriptRoot/.dotnet/packs/Microsoft.AspNetCore.App.Ref" + if (Test-Path $packsDir) + { + Write-Verbose "Found reference packs directory: $packsDir" # List existing reference pack versions - $existingRefPacks = Get-ChildItem $packsDir -ErrorAction SilentlyContinue; - if ($existingRefPacks) { - Write-Verbose "Existing reference pack versions: $($existingRefPacks.Name -join ', ')"; + $existingRefPacks = Get-ChildItem $packsDir -ErrorAction SilentlyContinue + if ($existingRefPacks) + { + Write-Verbose "Existing reference pack versions: $($existingRefPacks.Name -join ', ')" # Check if dev version of reference assemblies exist in the runtime zip - $devRefAssembliesSource = "$PSScriptRoot/.runtime/ref/Microsoft.AspNetCore.App"; - if (Test-Path $devRefAssembliesSource) { - Write-Verbose "Found dev reference assemblies in runtime zip at: $devRefAssembliesSource"; + $devRefAssembliesSource = "$PSScriptRoot/.runtime/ref/Microsoft.AspNetCore.App" + if (Test-Path $devRefAssembliesSource) + { + Write-Verbose "Found dev reference assemblies in runtime zip at: $devRefAssembliesSource" # Create dev version reference pack directory - $devRefPackDir = "$packsDir/10.0.0-dev"; - New-Item -Path $devRefPackDir -ItemType Directory -Force | Out-Null; + $devRefPackDir = "$packsDir/10.0.0-dev" + New-Item -Path $devRefPackDir -ItemType Directory -Force | Out-Null # Copy reference assemblies structure - Write-Verbose "Copying dev reference assemblies to: $devRefPackDir"; - Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force; + Write-Verbose "Copying dev reference assemblies to: $devRefPackDir" + Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force - Write-Verbose "Successfully created dev reference pack at $devRefPackDir"; + Write-Verbose "Successfully created dev reference pack at $devRefPackDir" # [dll check] 5) Check reference assembly - $devRefDiagnosticsDll = "$devRefPackDir/ref/net10.0/Microsoft.AspNetCore.Diagnostics.dll"; - Check-DiagnosticsDll -Path $devRefDiagnosticsDll -Description "5) Dev reference Microsoft.AspNetCore.Diagnostics.dll"; + $devRefDiagnosticsDll = "$devRefPackDir/ref/net10.0/Microsoft.AspNetCore.Diagnostics.dll" + Check-DiagnosticsDll -Path $devRefDiagnosticsDll -Description "5) Dev reference Microsoft.AspNetCore.Diagnostics.dll" # Upload the packs directory to CI artifacts for analysis - if (Test-Path "$PSScriptRoot/.dotnet/packs") { - $packsUploadPath = "$PSScriptRoot/.dotnet/packs"; - Write-Verbose "Uploading packs directory to CI artifacts: $packsUploadPath"; - Write-Host "##vso[artifact.upload containerfolder=packs-after;artifactname=packs-after]$packsUploadPath"; + if (Test-Path "$PSScriptRoot/.dotnet/packs") + { + $packsUploadPath = "$PSScriptRoot/.dotnet/packs" + Write-Verbose "Uploading packs directory to CI artifacts: $packsUploadPath" + Write-Host "##vso[artifact.upload containerfolder=packs-after;artifactname=packs-after]$packsUploadPath" } - } else { - Write-Warning "No dev reference assemblies found in runtime zip - reference assemblies not patched!"; + } + else + { + Write-Warning "No dev reference assemblies found in runtime zip - reference assemblies not patched!" # Alternative: try to copy from the latest preview version and replace specific DLLs - $latestRefPack = $existingRefPacks | Sort-Object Name -Descending | Select-Object -First 1; - if ($latestRefPack) { - Write-Verbose "Attempting to create dev reference pack based on: $($latestRefPack.Name)"; - $devRefPackDir = "$packsDir/10.0.0-dev"; + $latestRefPack = $existingRefPacks | Sort-Object Name -Descending | Select-Object -First 1 + if ($latestRefPack) + { + Write-Verbose "Attempting to create dev reference pack based on: $($latestRefPack.Name)" + $devRefPackDir = "$packsDir/10.0.0-dev" # Copy the latest reference pack as base - Copy-Item -Path $latestRefPack.FullName -Destination $devRefPackDir -Recurse -Force; + Copy-Item -Path $latestRefPack.FullName -Destination $devRefPackDir -Recurse -Force # Replace specific reference DLLs with runtime DLLs (not ideal but might work) - $runtimeDiagnosticsDll = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev/Microsoft.AspNetCore.Diagnostics.dll"; - $refDiagnosticsDll = "$devRefPackDir/ref/net10.0/Microsoft.AspNetCore.Diagnostics.dll"; - - if ((Test-Path $runtimeDiagnosticsDll) -and (Test-Path (Split-Path $refDiagnosticsDll))) { - Copy-Item -Path $runtimeDiagnosticsDll -Destination $refDiagnosticsDll -Force; - Write-Verbose "Replaced reference Microsoft.AspNetCore.Diagnostics.dll with runtime version"; - Check-DiagnosticsDll -Path $refDiagnosticsDll -Description "5) Patched reference Microsoft.AspNetCore.Diagnostics.dll"; + $runtimeDiagnosticsDll = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev/Microsoft.AspNetCore.Diagnostics.dll" + $refDiagnosticsDll = "$devRefPackDir/ref/net10.0/Microsoft.AspNetCore.Diagnostics.dll" + + if ((Test-Path $runtimeDiagnosticsDll) -and (Test-Path (Split-Path $refDiagnosticsDll))) + { + Copy-Item -Path $runtimeDiagnosticsDll -Destination $refDiagnosticsDll -Force + Write-Verbose "Replaced reference Microsoft.AspNetCore.Diagnostics.dll with runtime version" + Check-DiagnosticsDll -Path $refDiagnosticsDll -Description "5) Patched reference Microsoft.AspNetCore.Diagnostics.dll" } } } } - } else { - Write-Warning "Reference packs directory not found at $packsDir"; + } + else + { + Write-Warning "Reference packs directory not found at $packsDir" } Write-Verbose "=== SETTING UP ENVIRONMENT ===" From 555726acddc5ed5d537cd82c0b3afad69f83b290 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Mon, 28 Jul 2025 17:47:11 +0200 Subject: [PATCH 12/16] syntax. --- src/ProjectTemplates/scripts/Test-Template.psm1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 34c92037f24e..3b03b7f58196 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -123,6 +123,7 @@ function Test-Template { Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force; Write-Verbose "Successfully copied dev reference assemblies to $devRefPackDir"; } + if (-not (Check-DiagnosticsDll -Path $artifactsDiagnosticsDll -Description "3) Artifacts Microsoft.AspNetCore.Diagnostics.dll")) { # Try alternative location $artifactsDiagnosticsDll2 = "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/Microsoft.AspNetCore.Diagnostics.$TargetFramework.*.nupkg"; $artifactsNupkg = Get-ChildItem $artifactsDiagnosticsDll2 -ErrorAction SilentlyContinue | Select-Object -First 1; @@ -441,6 +442,7 @@ function Test-Template { } else { Write-Warning "Publish binlog not found at $publishBinlogPath"; } + Write-Host "##vso[artifact.upload containerfolder=repo-full;artifactname=repo-full]$PSScriptRoot/../../.." } finally { Pop-Location -StackName TemplateFolder; From 0c90250af70ac71ba608af32a9fa56d946612f19 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Tue, 29 Jul 2025 07:58:53 +0200 Subject: [PATCH 13/16] Syntax. --- .../scripts/Test-Template.psm1 | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 3b03b7f58196..5354e3046e8a 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -99,6 +99,10 @@ function Test-Template { } } + + # Always set $packsDir before any use + $packsDir = "$PSScriptRoot/.dotnet/packs/Microsoft.AspNetCore.App.Ref" + Write-Verbose "Patching Microsoft.AspNetCore.App"; # [dll check] 1) Check Microsoft.AspNetCore.Diagnostics.dll in PSScriptRoot before patching @@ -106,22 +110,24 @@ function Test-Template { Check-DiagnosticsDll -Path $psScriptDiagnosticsDll -Description "1) PSScriptRoot Microsoft.AspNetCore.Diagnostics.dll before patching"; # Remove all existing subdirectories (old versions) - Get-ChildItem $packsDir -Directory | Remove-Item -Recurse -Force -ErrorAction Ignore; - Write-Verbose "Removed all existing reference pack versions from: $packsDir"; + if (Test-Path $packsDir) { + Get-ChildItem $packsDir -Directory | Remove-Item -Recurse -Force -ErrorAction Ignore + Write-Verbose "Removed all existing reference pack versions from: $packsDir" + } # Check if dev version of reference assemblies exist in the runtime zip - $devRefAssembliesSource = "$PSScriptRoot/.runtime/ref/Microsoft.AspNetCore.App"; + $devRefAssembliesSource = "$PSScriptRoot/.runtime/ref/Microsoft.AspNetCore.App" if (Test-Path $devRefAssembliesSource) { - Write-Verbose "Found dev reference assemblies in runtime zip at: $devRefAssembliesSource"; - $devRefPackDir = "$packsDir/10.0.0-dev"; + Write-Verbose "Found dev reference assemblies in runtime zip at: $devRefAssembliesSource" + $devRefPackDir = "$packsDir/10.0.0-dev" # Remove any existing dev reference pack directory first if (Test-Path $devRefPackDir) { - Remove-Item -Path $devRefPackDir -Recurse -Force -ErrorAction Ignore; + Remove-Item -Path $devRefPackDir -Recurse -Force -ErrorAction Ignore } - New-Item -Path $devRefPackDir -ItemType Directory -Force | Out-Null; + New-Item -Path $devRefPackDir -ItemType Directory -Force | Out-Null # Copy the entire structure from the dev ref assemblies source - Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force; - Write-Verbose "Successfully copied dev reference assemblies to $devRefPackDir"; + Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force + Write-Verbose "Successfully copied dev reference assemblies to $devRefPackDir" } if (-not (Check-DiagnosticsDll -Path $artifactsDiagnosticsDll -Description "3) Artifacts Microsoft.AspNetCore.Diagnostics.dll")) { # Try alternative location @@ -236,7 +242,6 @@ function Test-Template { Write-Verbose "=== PATCHING REFERENCE ASSEMBLIES ===" # Find the reference pack directory - $packsDir = "$PSScriptRoot/.dotnet/packs/Microsoft.AspNetCore.App.Ref" if (Test-Path $packsDir) { Write-Verbose "Found reference packs directory: $packsDir" From 66e74dc0ef911dde75af0ce692f0f3661eb7778a Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Tue, 29 Jul 2025 10:46:22 +0200 Subject: [PATCH 14/16] Missing artifactsDiagnosticsDll + fix `Length` error. --- src/ProjectTemplates/scripts/Test-Template.psm1 | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index 5354e3046e8a..f54bc2b6a8fb 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -109,6 +109,9 @@ function Test-Template { $psScriptDiagnosticsDll = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev/Microsoft.AspNetCore.Diagnostics.dll"; Check-DiagnosticsDll -Path $psScriptDiagnosticsDll -Description "1) PSScriptRoot Microsoft.AspNetCore.Diagnostics.dll before patching"; + # Initialize artifactsDiagnosticsDll path + $artifactsDiagnosticsDll = "$PSScriptRoot/../../../artifacts/bin/Microsoft.AspNetCore.Diagnostics/$Configuration/$TargetFramework/Microsoft.AspNetCore.Diagnostics.dll" + # Remove all existing subdirectories (old versions) if (Test-Path $packsDir) { Get-ChildItem $packsDir -Directory | Remove-Item -Recurse -Force -ErrorAction Ignore @@ -379,7 +382,7 @@ function Test-Template { New-Item -ErrorAction Ignore -Path $tmpDir -ItemType Directory | Out-Null; Push-Location $tmpDir -StackName TemplateFolder; try { - $TemplateArguments = , "new" + $TemplateArguments + , "--no-restore"; + $TemplateArguments = @("new") + @($TemplateArguments) + @("--no-restore"); Write-Verbose "Running dotnet command with arguments: $TemplateArguments"; Write-Verbose "Current working directory: $(Get-Location)" Write-Verbose "About to run dotnet new - checking dotnet version one more time:" @@ -390,9 +393,9 @@ function Test-Template { Write-Verbose "Template creation completed. Checking created files:" Get-ChildItem . -Recurse -File | Select-Object -First 10 | ForEach-Object { Write-Verbose " $($_.FullName)" } - $proj = Get-ChildItem $tmpDir -Recurse -File -Filter '*.csproj' -Depth 3; - if ($proj.Length -eq 0) { - $proj = Get-ChildItem $tmpDir -Recurse -File -Filter '*.fsproj' -Depth 3; + $proj = @(Get-ChildItem $tmpDir -Recurse -File -Filter '*.csproj' -Depth 3) + if ($proj.Count -eq 0) { + $proj = @(Get-ChildItem $tmpDir -Recurse -File -Filter '*.fsproj' -Depth 3) } $importPath = "$PSScriptRoot/../test/Templates.Tests/bin/$Configuration/$TargetFramework/TestTemplates"; From 710318607cf391a17a2a1e5759df4ac3c72e7489 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Tue, 29 Jul 2025 11:59:08 +0200 Subject: [PATCH 15/16] Fix job run + more robust. --- .../scripts/Test-Template.psm1 | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index f54bc2b6a8fb..a5c8c268e604 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -109,29 +109,38 @@ function Test-Template { $psScriptDiagnosticsDll = "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/10.0.0-dev/Microsoft.AspNetCore.Diagnostics.dll"; Check-DiagnosticsDll -Path $psScriptDiagnosticsDll -Description "1) PSScriptRoot Microsoft.AspNetCore.Diagnostics.dll before patching"; - # Initialize artifactsDiagnosticsDll path - $artifactsDiagnosticsDll = "$PSScriptRoot/../../../artifacts/bin/Microsoft.AspNetCore.Diagnostics/$Configuration/$TargetFramework/Microsoft.AspNetCore.Diagnostics.dll" + # Find the built runtime zip file + $builtRuntimePattern = "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/aspnetcore-runtime-*-dev-win-x64.zip" + $builtRuntime = Get-ChildItem $builtRuntimePattern -ErrorAction SilentlyContinue | Select-Object -First 1 | Select-Object -ExpandProperty FullName + if (-not $builtRuntime) { + Write-Error "Built runtime package not found at pattern: $builtRuntimePattern. Ensure the main build has completed with -pack option." + return + } + Write-Verbose "Built runtime package: $builtRuntime"; - # Remove all existing subdirectories (old versions) - if (Test-Path $packsDir) { - Get-ChildItem $packsDir -Directory | Remove-Item -Recurse -Force -ErrorAction Ignore - Write-Verbose "Removed all existing reference pack versions from: $packsDir" - } + # [dll check] 3) Check Microsoft.AspNetCore.Diagnostics.dll in artifacts + $artifactsDiagnosticsDll = "$PSScriptRoot/../../../artifacts/bin/Microsoft.AspNetCore.Diagnostics/$Configuration/$TargetFramework/Microsoft.AspNetCore.Diagnostics.dll"; - # Check if dev version of reference assemblies exist in the runtime zip - $devRefAssembliesSource = "$PSScriptRoot/.runtime/ref/Microsoft.AspNetCore.App" - if (Test-Path $devRefAssembliesSource) { - Write-Verbose "Found dev reference assemblies in runtime zip at: $devRefAssembliesSource" - $devRefPackDir = "$packsDir/10.0.0-dev" - # Remove any existing dev reference pack directory first - if (Test-Path $devRefPackDir) { - Remove-Item -Path $devRefPackDir -Recurse -Force -ErrorAction Ignore - } - New-Item -Path $devRefPackDir -ItemType Directory -Force | Out-Null - # Copy the entire structure from the dev ref assemblies source - Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force - Write-Verbose "Successfully copied dev reference assemblies to $devRefPackDir" + # Remove all existing subdirectories (old versions) + if (Test-Path $packsDir) { + Get-ChildItem $packsDir -Directory | Remove-Item -Recurse -Force -ErrorAction Ignore + Write-Verbose "Removed all existing reference pack versions from: $packsDir" + } + + # Check if dev version of reference assemblies exist in the runtime zip + $devRefAssembliesSource = "$PSScriptRoot/.runtime/ref/Microsoft.AspNetCore.App" + if (Test-Path $devRefAssembliesSource) { + Write-Verbose "Found dev reference assemblies in runtime zip at: $devRefAssembliesSource" + $devRefPackDir = "$packsDir/10.0.0-dev" + # Remove any existing dev reference pack directory first + if (Test-Path $devRefPackDir) { + Remove-Item -Path $devRefPackDir -Recurse -Force -ErrorAction Ignore } + New-Item -Path $devRefPackDir -ItemType Directory -Force | Out-Null + # Copy the entire structure from the dev ref assemblies source + Copy-Item -Path "$devRefAssembliesSource/*" -Destination $devRefPackDir -Recurse -Force + Write-Verbose "Successfully copied dev reference assemblies to $devRefPackDir" + } if (-not (Check-DiagnosticsDll -Path $artifactsDiagnosticsDll -Description "3) Artifacts Microsoft.AspNetCore.Diagnostics.dll")) { # Try alternative location $artifactsDiagnosticsDll2 = "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/Microsoft.AspNetCore.Diagnostics.$TargetFramework.*.nupkg"; From cf1139117c12cc577c9268f1be923f7fd64d2f60 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz Date: Wed, 30 Jul 2025 10:54:53 +0200 Subject: [PATCH 16/16] Limit upload to the ProjectTemplates dir. --- src/ProjectTemplates/scripts/Test-Template.psm1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ProjectTemplates/scripts/Test-Template.psm1 b/src/ProjectTemplates/scripts/Test-Template.psm1 index a5c8c268e604..80a941a1e0f7 100644 --- a/src/ProjectTemplates/scripts/Test-Template.psm1 +++ b/src/ProjectTemplates/scripts/Test-Template.psm1 @@ -459,7 +459,7 @@ function Test-Template { } else { Write-Warning "Publish binlog not found at $publishBinlogPath"; } - Write-Host "##vso[artifact.upload containerfolder=repo-full;artifactname=repo-full]$PSScriptRoot/../../.." + Write-Host "##vso[artifact.upload containerfolder=project-templates;artifactname=project-templates]$PSScriptRoot/../.." } finally { Pop-Location -StackName TemplateFolder;