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/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(); 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 9f63b5201cae..80a941a1e0f7 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 ( @@ -18,37 +34,339 @@ 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 " $_" } + } } + + # Always set $packsDir before any use + $packsDir = "$PSScriptRoot/.dotnet/packs/Microsoft.AspNetCore.App.Ref" + 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" }; + + # [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"; + + # 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"; + + # [dll check] 3) Check Microsoft.AspNetCore.Diagnostics.dll in artifacts + $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 + 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"; + $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"; + + # 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; - Remove-Item "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/*-dev" -Recurse -ErrorAction Ignore; + + 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)" } + } + + # [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"; + 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 "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 ASP.NET Core 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") { + 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"; - 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)" } + } + + # 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..."; + + # [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 (-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 "[dll check] Dev runtime folder not found at $devRuntimePath"; + } + + # ===== PATCH REFERENCE ASSEMBLIES ===== + Write-Verbose "=== PATCHING REFERENCE ASSEMBLIES ===" + + # Find the reference pack directory + 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" + + # 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!" + + # 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"; + 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; - Push-Location ..; - try { - 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; + Write-Verbose "Template package name: $PackageName" if (-not (Test-Path "$($env:USERPROFILE)/.templateengine/packages/$PackageName")) { Write-Verbose "Installing package from $PackagePath"; @@ -73,13 +391,20 @@ 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:" + dotnet --version | ForEach-Object { Write-Verbose " $_" } + dotnet @TemplateArguments; - $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; + 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.Count -eq 0) { + $proj = @(Get-ChildItem $tmpDir -Recurse -File -Filter '*.fsproj' -Depth 3) } $importPath = "$PSScriptRoot/../test/Templates.Tests/bin/$Configuration/$TargetFramework/TestTemplates"; @@ -119,8 +444,22 @@ function Test-Template { } $publishOutputDir = "./.publish"; - Write-Verbose "Running dotnet publish --configuration $Configuration --output $publishOutputDir"; - dotnet.exe publish --configuration $Configuration --output $publishOutputDir; + $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 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"; + } + Write-Host "##vso[artifact.upload containerfolder=project-templates;artifactname=project-templates]$PSScriptRoot/../.." } finally { Pop-Location -StackName TemplateFolder;