Skip to content

Commit 538b580

Browse files
committed
Debugging.
1 parent b83721c commit 538b580

File tree

2 files changed

+177
-0
lines changed

2 files changed

+177
-0
lines changed

eng/build.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,50 @@ Remove-Item variable:global:_MSBuildExe -ea Ignore
373373
# Import Arcade
374374
. "$PSScriptRoot/common/tools.ps1"
375375

376+
# Add debugging for .NET environment after tools.ps1 import
377+
Write-Host "=== BUILD.PS1 DOTNET ENVIRONMENT DEBUG START ===" -ForegroundColor Yellow
378+
Write-Host "Repository root: $RepoRoot" -ForegroundColor Cyan
379+
Write-Host "Current DOTNET_ROOT: $($env:DOTNET_ROOT)" -ForegroundColor Cyan
380+
Write-Host "Current DOTNET_ROOT_X86: $($env:DOTNET_ROOT_X86)" -ForegroundColor Cyan
381+
Write-Host "Current DOTNET_MULTILEVEL_LOOKUP: $($env:DOTNET_MULTILEVEL_LOOKUP)" -ForegroundColor Cyan
382+
Write-Host "Current PATH (first 300 chars): $($env:PATH.Substring(0, [Math]::Min(300, $env:PATH.Length)))" -ForegroundColor Cyan
383+
384+
# Check what Get-Command dotnet finds after tools.ps1
385+
$buildDotnetCommand = Get-Command dotnet -ErrorAction SilentlyContinue
386+
if ($buildDotnetCommand) {
387+
Write-Host "Get-Command dotnet found: $($buildDotnetCommand.Source)" -ForegroundColor Cyan
388+
Write-Host "Build dotnet version:" -ForegroundColor Cyan
389+
& $buildDotnetCommand.Source --version | ForEach-Object { Write-Host " $_" -ForegroundColor Cyan }
390+
Write-Host "Build dotnet --info:" -ForegroundColor Cyan
391+
& $buildDotnetCommand.Source --info | ForEach-Object { Write-Host " $_" -ForegroundColor Cyan }
392+
} else {
393+
Write-Host "Get-Command dotnet found: NONE" -ForegroundColor Red
394+
}
395+
396+
# Check repository .dotnet folder
397+
$repoDotnetPath = "$RepoRoot\.dotnet"
398+
Write-Host "Repository .dotnet path: $repoDotnetPath" -ForegroundColor Cyan
399+
Write-Host "Repository .dotnet exists: $(Test-Path $repoDotnetPath)" -ForegroundColor Cyan
400+
if (Test-Path $repoDotnetPath) {
401+
Write-Host "Repository .dotnet contents:" -ForegroundColor Cyan
402+
Get-ChildItem $repoDotnetPath -ErrorAction SilentlyContinue | ForEach-Object { Write-Host " $($_.Name)" -ForegroundColor Cyan }
403+
404+
$repoDotnetExe = "$repoDotnetPath\dotnet.exe"
405+
if (Test-Path $repoDotnetExe) {
406+
Write-Host "Repository dotnet version:" -ForegroundColor Cyan
407+
& $repoDotnetExe --version | ForEach-Object { Write-Host " $_" -ForegroundColor Cyan }
408+
}
409+
}
410+
411+
# Check global.json
412+
$globalJsonPath = "$RepoRoot\global.json"
413+
if (Test-Path $globalJsonPath) {
414+
Write-Host "global.json content:" -ForegroundColor Cyan
415+
Get-Content $globalJsonPath | ForEach-Object { Write-Host " $_" -ForegroundColor Cyan }
416+
}
417+
418+
Write-Host "=== BUILD.PS1 DOTNET ENVIRONMENT DEBUG END ===" -ForegroundColor Yellow
419+
376420
function LocateJava {
377421
$foundJdk = $false
378422
$javac = Get-Command javac -ErrorAction Ignore -CommandType Application
@@ -501,6 +545,8 @@ try {
501545
if (-not $OnlyBuildRepoTasks) {
502546
if ($performDesktopBuild) {
503547
Write-Host
548+
Write-Host "=== PERFORMING DESKTOP BUILD ===" -ForegroundColor Yellow
549+
Write-Host "MSBuild engine: vs (desktop)" -ForegroundColor Cyan
504550
Remove-Item variable:global:_BuildTool -ErrorAction Ignore
505551
$msbuildEngine = 'vs'
506552

@@ -509,14 +555,32 @@ try {
509555
$MSBuildOnlyArguments += $dotnetBuildArguments
510556
}
511557

558+
Write-Host "MSBuild arguments: @MSBuildArguments @MSBuildOnlyArguments" -ForegroundColor Cyan
559+
Write-Host "About to run desktop MSBuild - checking environment:" -ForegroundColor Cyan
560+
$currentDotnet = Get-Command dotnet -ErrorAction SilentlyContinue
561+
if ($currentDotnet) {
562+
Write-Host "Current dotnet: $($currentDotnet.Source)" -ForegroundColor Cyan
563+
& $currentDotnet.Source --version | ForEach-Object { Write-Host " Version: $_" -ForegroundColor Cyan }
564+
}
565+
512566
MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments @MSBuildOnlyArguments
513567
}
514568

515569
if ($performDotnetBuild) {
516570
Write-Host
571+
Write-Host "=== PERFORMING DOTNET BUILD ===" -ForegroundColor Yellow
572+
Write-Host "MSBuild engine: dotnet" -ForegroundColor Cyan
517573
Remove-Item variable:global:_BuildTool -ErrorAction Ignore
518574
$msbuildEngine = 'dotnet'
519575

576+
Write-Host "MSBuild arguments: @MSBuildArguments @dotnetBuildArguments" -ForegroundColor Cyan
577+
Write-Host "About to run dotnet MSBuild - checking environment:" -ForegroundColor Cyan
578+
$currentDotnet = Get-Command dotnet -ErrorAction SilentlyContinue
579+
if ($currentDotnet) {
580+
Write-Host "Current dotnet: $($currentDotnet.Source)" -ForegroundColor Cyan
581+
& $currentDotnet.Source --version | ForEach-Object { Write-Host " Version: $_" -ForegroundColor Cyan }
582+
}
583+
520584
MSBuild $toolsetBuildProj /p:RepoRoot=$RepoRoot @MSBuildArguments @dotnetBuildArguments
521585
}
522586
}

src/ProjectTemplates/scripts/Test-Template.psm1

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,140 @@ function Test-Template {
1818
[string] $TargetFramework = "net10.0"
1919
)
2020

21+
Write-Verbose "=== DOTNET ENVIRONMENT DEBUG START ==="
22+
Write-Verbose "PSScriptRoot: $PSScriptRoot"
23+
Write-Verbose "Current DOTNET_ROOT: $($env:DOTNET_ROOT)"
24+
Write-Verbose "Current DOTNET_ROOT_X86: $($env:DOTNET_ROOT_X86)"
25+
Write-Verbose "Current PATH: $($env:PATH)"
26+
27+
# Check what Get-Command dotnet finds
28+
$dotnetCommand = Get-Command dotnet -ErrorAction SilentlyContinue
29+
if ($dotnetCommand) {
30+
Write-Verbose "Get-Command dotnet found: $($dotnetCommand.Source)"
31+
Write-Verbose "Dotnet version from Get-Command location:"
32+
& $dotnetCommand.Source --version | ForEach-Object { Write-Verbose " $_" }
33+
} else {
34+
Write-Verbose "Get-Command dotnet found: NONE"
35+
}
36+
2137
if(-not (Test-Path "$PSScriptRoot/.dotnet")){
38+
Write-Verbose "Local .dotnet folder does not exist, creating it..."
39+
40+
# Original logic: use Get-Command dotnet
2241
$dotnetFolder = Get-Command dotnet | Select-Object -ExpandProperty Source | Split-Path -Parent;
42+
Write-Verbose "Dotnet folder from Get-Command: $dotnetFolder"
43+
44+
# Let's also check what's in the repo root
45+
$repoRoot = "$PSScriptRoot/../../../";
46+
$repoDotnetFolder = "$repoRoot/.dotnet";
47+
Write-Verbose "Repository root: $repoRoot"
48+
Write-Verbose "Repository .dotnet folder: $repoDotnetFolder"
49+
Write-Verbose "Repository .dotnet exists: $(Test-Path $repoDotnetFolder)"
50+
51+
if (Test-Path $repoDotnetFolder) {
52+
Write-Verbose "Repository .dotnet contents:"
53+
Get-ChildItem $repoDotnetFolder -ErrorAction SilentlyContinue | ForEach-Object { Write-Verbose " $($_.Name)" }
54+
55+
# Check version in repo dotnet
56+
$repoDotnetExe = "$repoDotnetFolder/dotnet.exe"
57+
if (Test-Path $repoDotnetExe) {
58+
Write-Verbose "Repository dotnet version:"
59+
& $repoDotnetExe --version | ForEach-Object { Write-Verbose " $_" }
60+
}
61+
}
62+
2363
Write-Verbose "Copying dotnet folder from $dotnetFolder to $PSScriptRoot/.dotnet";
2464
Copy-Item -Path $dotnetFolder -Destination "$PSScriptRoot/.dotnet" -Recurse;
65+
66+
Write-Verbose "Copy completed. Verifying local .dotnet folder..."
67+
if (Test-Path "$PSScriptRoot/.dotnet") {
68+
Write-Verbose "Local .dotnet folder created successfully"
69+
$localDotnetExe = "$PSScriptRoot/.dotnet/dotnet.exe"
70+
if (Test-Path $localDotnetExe) {
71+
Write-Verbose "Local dotnet version after copy:"
72+
& $localDotnetExe --version | ForEach-Object { Write-Verbose " $_" }
73+
}
74+
} else {
75+
Write-Verbose "ERROR: Local .dotnet folder was not created!"
76+
}
77+
} else {
78+
Write-Verbose "Local .dotnet folder already exists"
79+
$localDotnetExe = "$PSScriptRoot/.dotnet/dotnet.exe"
80+
if (Test-Path $localDotnetExe) {
81+
Write-Verbose "Existing local dotnet version:"
82+
& $localDotnetExe --version | ForEach-Object { Write-Verbose " $_" }
83+
}
2584
}
2685

2786
Write-Verbose "Patching Microsoft.AspNetCore.App";
2887
$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" };
88+
Write-Verbose "Built runtime package: $builtRuntime";
2989
Write-Verbose "Patching Microsoft.AspNetCore.App from $builtRuntime";
3090
Remove-Item "$PSScriptRoot/.runtime" -Recurse -ErrorAction Ignore;
3191
Expand-Archive -Path $builtRuntime -DestinationPath "$PSScriptRoot/.runtime" -Force;
92+
93+
Write-Verbose "Extracted runtime contents:";
94+
if (Test-Path "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App") {
95+
Get-ChildItem "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" }
96+
}
97+
98+
Write-Verbose "Removing existing dev runtimes from local .dotnet...";
3299
Remove-Item "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App/*-dev" -Recurse -ErrorAction Ignore;
100+
101+
Write-Verbose "Before patching - local .dotnet ASP.NET Core runtimes:";
102+
if (Test-Path "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App") {
103+
Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" }
104+
}
105+
33106
Write-Verbose "Copying $PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App to $PSScriptRoot/.dotnet/shared";
34107
Copy-Item -Path "$PSScriptRoot/.runtime/shared/Microsoft.AspNetCore.App" -Destination "$PSScriptRoot/.dotnet/shared" -Recurse -Force;
35108

109+
Write-Verbose "After patching - local .dotnet ASP.NET Core runtimes:";
110+
if (Test-Path "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App") {
111+
Get-ChildItem "$PSScriptRoot/.dotnet/shared/Microsoft.AspNetCore.App" | ForEach-Object { Write-Verbose " $($_.Name)" }
112+
}
113+
114+
Write-Verbose "=== SETTING UP ENVIRONMENT ==="
115+
Write-Verbose "Setting DOTNET_ROOT to: $PSScriptRoot/.dotnet"
36116
$env:DOTNET_ROOT = "$PSScriptRoot/.dotnet";
117+
Write-Verbose "Setting DOTNET_ROOT_X86 to: $PSScriptRoot/.dotnet"
37118
$env:DOTNET_ROOT_X86 = "$PSScriptRoot/.dotnet";
119+
Write-Verbose "Prepending to PATH: $PSScriptRoot/.dotnet"
38120
$env:Path = "$PSScriptRoot/.dotnet;$env:Path";
121+
122+
Write-Verbose "Final environment variables:"
123+
Write-Verbose " DOTNET_ROOT: $($env:DOTNET_ROOT)"
124+
Write-Verbose " DOTNET_ROOT_X86: $($env:DOTNET_ROOT_X86)"
125+
Write-Verbose " PATH (first 200 chars): $($env:PATH.Substring(0, [Math]::Min(200, $env:PATH.Length)))"
126+
127+
# Verify which dotnet we'll use after env changes
128+
$finalDotnetCommand = Get-Command dotnet -ErrorAction SilentlyContinue
129+
if ($finalDotnetCommand) {
130+
Write-Verbose "After env setup, Get-Command dotnet finds: $($finalDotnetCommand.Source)"
131+
Write-Verbose "Final dotnet version:"
132+
& $finalDotnetCommand.Source --version | ForEach-Object { Write-Verbose " $_" }
133+
Write-Verbose "Final dotnet --info:"
134+
& $finalDotnetCommand.Source --info | ForEach-Object { Write-Verbose " $_" }
135+
}
136+
Write-Verbose "=== DOTNET ENVIRONMENT DEBUG END ==="
39137
$tmpDir = "$PSScriptRoot/$templateName";
138+
Write-Verbose "Template working directory: $tmpDir"
40139
Remove-Item -Path $tmpDir -Recurse -ErrorAction Ignore;
140+
Write-Verbose "Running dotnet pack to build template packages..."
41141
Push-Location ..;
42142
try {
143+
Write-Verbose "Current location for dotnet pack: $(Get-Location)"
43144
dotnet pack
44145
}
45146
finally {
46147
Pop-Location;
47148
}
48149

49150
$PackagePath = Resolve-Path "$PSScriptRoot/../../../artifacts/packages/$Configuration/Shipping/$TemplatePackagePath";
151+
Write-Verbose "Template package path: $PackagePath"
50152

51153
$PackageName = (Get-Item $PackagePath).Name;
154+
Write-Verbose "Template package name: $PackageName"
52155

53156
if (-not (Test-Path "$($env:USERPROFILE)/.templateengine/packages/$PackageName")) {
54157
Write-Verbose "Installing package from $PackagePath";
@@ -75,8 +178,15 @@ function Test-Template {
75178
try {
76179
$TemplateArguments = , "new" + $TemplateArguments + , "--no-restore";
77180
Write-Verbose "Running dotnet command with arguments: $TemplateArguments";
181+
Write-Verbose "Current working directory: $(Get-Location)"
182+
Write-Verbose "About to run dotnet new - checking dotnet version one more time:"
183+
dotnet --version | ForEach-Object { Write-Verbose " $_" }
184+
78185
dotnet @TemplateArguments;
79186

187+
Write-Verbose "Template creation completed. Checking created files:"
188+
Get-ChildItem . -Recurse -File | Select-Object -First 10 | ForEach-Object { Write-Verbose " $($_.FullName)" }
189+
80190
$proj = Get-ChildItem $tmpDir -Recurse -File -Filter '*.csproj' -Depth 3;
81191
if ($proj.Length -eq 0) {
82192
$proj = Get-ChildItem $tmpDir -Recurse -File -Filter '*.fsproj' -Depth 3;
@@ -119,6 +229,9 @@ function Test-Template {
119229
}
120230

121231
$publishOutputDir = "./.publish";
232+
Write-Verbose "Publishing template to: $publishOutputDir"
233+
Write-Verbose "About to run dotnet publish - final dotnet version check:"
234+
dotnet --version | ForEach-Object { Write-Verbose " $_" }
122235
Write-Verbose "Running dotnet publish --configuration $Configuration --output $publishOutputDir";
123236
dotnet.exe publish --configuration $Configuration --output $publishOutputDir;
124237
}

0 commit comments

Comments
 (0)