From 424b3eb8aedb3a43a8bcd241d36f6dab3d7ffccf Mon Sep 17 00:00:00 2001 From: Zaldaryon <273555259+Zaldaryon@users.noreply.github.com> Date: Wed, 16 Sep 2026 18:37:27 -0300 Subject: [PATCH] Resolve dotnet for runtime-donor build so it works when the SDK is under the user profile prepare-runtime-donors built the exact donors with a bare `dotnet build`, which uses whatever `dotnet` is on PATH. When the .NET SDK is installed under %USERPROFILE%\.dotnet (or ~/.dotnet) and that directory is not on PATH, the donor build failed with "No .NET SDKs were found" even though the main solution had just built with that SDK. This is the third failure reported in issue #90. Resolve dotnet the same way the script already resolves ilspycmd: prefer one on PATH, then fall back to the user-profile install. When the resolved dotnet lives in the profile install, set DOTNET_ROOT to that directory so the host discovers the SDK there, matching what IlspycmdInstaller.cs does for the tool it spawns. Use the resolved path for both donor builds. Mirrored in the shell script for Linux and macOS. Verified on Windows: with dotnet on PATH the script runs end to end and reports "Runtime donors ready", 0 build errors. With dotnet removed from PATH and only a ~/.dotnet install present, the resolver picks the profile dotnet and sets DOTNET_ROOT. --- scripts/prepare-runtime-donors.ps1 | 32 ++++++++++++++++++++++++++++-- scripts/prepare-runtime-donors.sh | 25 +++++++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/scripts/prepare-runtime-donors.ps1 b/scripts/prepare-runtime-donors.ps1 index 0d52f2af..01730201 100644 --- a/scripts/prepare-runtime-donors.ps1 +++ b/scripts/prepare-runtime-donors.ps1 @@ -10,6 +10,34 @@ $ErrorActionPreference = 'Stop' $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $repoRoot = Split-Path -Parent $scriptDir . "$scriptDir/_exec.ps1" + +# Resolve dotnet the same way ilspycmd is resolved below: prefer one on PATH, +# then fall back to the user-profile install at ~/.dotnet. The installer and +# bootstrap can place the SDK under %USERPROFILE%\.dotnet without adding it to +# PATH, so a bare "dotnet" call from here found no SDK and the donor build died +# with "No .NET SDKs were found" (issue #90). When the resolved dotnet lives in +# the profile install, DOTNET_ROOT has to point at it so the host discovers the +# SDK there, matching what IlspycmdInstaller.cs does for the tool it spawns. +$dotnetCmd = Get-Command dotnet -ErrorAction SilentlyContinue +if ($dotnetCmd) { + $dotnetPath = $dotnetCmd.Source +} else { + $profileRoot = if ($env:USERPROFILE) { $env:USERPROFILE } else { $env:HOME } + $dotnetPath = Join-Path $profileRoot '.dotnet/dotnet.exe' + if (-not (Test-Path $dotnetPath)) { + $dotnetPath = Join-Path $profileRoot '.dotnet/dotnet' + } + if (-not (Test-Path $dotnetPath)) { + throw 'dotnet is required. Install the .NET SDK or run scripts/bootstrap.ps1 first.' + } +} +$dotnetDir = Split-Path -Parent $dotnetPath +$profileRootForCheck = if ($env:USERPROFILE) { $env:USERPROFILE } else { $env:HOME } +$profileDotnet = [IO.Path]::GetFullPath((Join-Path $profileRootForCheck '.dotnet')) +if ($dotnetDir -ieq $profileDotnet) { + $env:DOTNET_ROOT = $dotnetDir +} + if (-not $VanillaDir) { $VanillaDir = Join-Path $repoRoot '.vanilla/win-x64/vintagestory' } @@ -367,12 +395,12 @@ Remove-Item Env:Platform -ErrorAction SilentlyContinue $buildErrors = @() try { Write-Host " Building VSEssentials..." - Invoke-NativeStep { & dotnet build $essentialsProject -c $Configuration --nologo } + Invoke-NativeStep { & $dotnetPath build $essentialsProject -c $Configuration --nologo } if ($LASTEXITCODE -ne 0) { $buildErrors += 'VSEssentials' } Write-Host " Building VSSurvivalMod..." - Invoke-NativeStep { & dotnet build $survivalProject -c $Configuration --nologo } + Invoke-NativeStep { & $dotnetPath build $survivalProject -c $Configuration --nologo } if ($LASTEXITCODE -ne 0) { $buildErrors += 'VSSurvivalMod' } diff --git a/scripts/prepare-runtime-donors.sh b/scripts/prepare-runtime-donors.sh index bca3d549..f6f38738 100644 --- a/scripts/prepare-runtime-donors.sh +++ b/scripts/prepare-runtime-donors.sh @@ -11,6 +11,27 @@ vanilla_parent="$(cd -- "$vanilla_dir/.." && pwd)" runtime_donor_dir="${RUNTIME_DONOR_DIR:-$vanilla_parent/runtime-donors}" configuration="${CONFIGURATION:-Release}" runtime_root="$repo_root/.build/runtime-donors" + +# Resolve dotnet the same way the PowerShell mirror does: prefer one on PATH, +# then fall back to the user-profile install at ~/.dotnet. The installer and +# bootstrap can place the SDK under $HOME/.dotnet without adding it to PATH, so +# a bare "dotnet" call from here found no SDK and the donor build died with +# "No .NET SDKs were found" (issue #90). When the resolved dotnet lives in the +# profile install, DOTNET_ROOT has to point at it so the host discovers the SDK +# there. +if command -v dotnet >/dev/null 2>&1; then + dotnet_cmd="$(command -v dotnet)" +elif [[ -x "$HOME/.dotnet/dotnet" ]]; then + dotnet_cmd="$HOME/.dotnet/dotnet" +else + echo "dotnet is required. Install the .NET SDK or run scripts/bootstrap.sh first." >&2 + exit 1 +fi +dotnet_dir="$(cd -- "$(dirname -- "$dotnet_cmd")" && pwd)" +if [[ "$dotnet_dir" == "$HOME/.dotnet" ]]; then + export DOTNET_ROOT="$dotnet_dir" +fi + contracts_dll="$repo_root/bin/$configuration/net10.0/Optimum.Api.Contracts.dll" game_content_dll="$repo_root/bin/$configuration/net10.0/Optimum.GameContent.dll" api_dll="$repo_root/bin/$configuration/net10.0/VintagestoryAPI.dll" @@ -350,13 +371,13 @@ unset Platform build_errors="" if [[ " ${eligible_projects[*]} " == *" VSEssentials "* ]]; then echo " Building VSEssentials..." - if ! dotnet build "$essentials_project" -c "$configuration" --nologo; then + if ! "$dotnet_cmd" build "$essentials_project" -c "$configuration" --nologo; then build_errors="${build_errors}VSEssentials " fi fi if [[ " ${eligible_projects[*]} " == *" VSSurvivalMod "* ]]; then echo " Building VSSurvivalMod..." - if ! dotnet build "$survival_project" -c "$configuration" --nologo; then + if ! "$dotnet_cmd" build "$survival_project" -c "$configuration" --nologo; then build_errors="${build_errors}VSSurvivalMod " fi fi