@@ -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