Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

The build puts the first dotnet with an SDK 10 in front, and the .NET row follows it

Aaron Oliphant5ee691c9ac04
diff --git a/frontend-qt/nspb_qt/localization.py b/frontend-qt/nspb_qt/localization.py
index 7c967576..0406a382 100644
--- a/frontend-qt/nspb_qt/localization.py
+++ b/frontend-qt/nspb_qt/localization.py
@@ -722,7 +722,6 @@ TABLE: dict[str, tuple[str, str, str, str]] = {
'dep.dotnet': ('.NET SDK 10', '.NET SDK 10', '.NET SDK 10', '.NET SDK 10'),
'dep.dotnet.hint': ('dotnet-install.sh 装到 ~/.dotnet', 'dotnet-install.sh into ~/.dotnet', 'dotnet-install.sh till ~/.dotnet', 'dotnet-install.sh nach ~/.dotnet'),
'dep.dotnet.missing': ('没找到带 SDK 10 的 dotnet', 'no dotnet with SDK 10 found', 'ingen dotnet med SDK 10 hittades', 'kein dotnet mit SDK 10 gefunden'),
- 'dep.dotnet.shadowed': ('构建会先用 %@,它没有 SDK 10。点「修复」把 %@ 放到它前面', 'the build runs %@, which has no SDK 10. Fix puts %@ in front of it', 'bygget kör %@, som saknar SDK 10. Åtgärda lägger %@ före den', 'der Build nutzt %@, das kein SDK 10 hat. Beheben stellt %@ davor'),
'dep.dotnet.downloading': ('正在下载 .NET SDK 10…(约 287 MB,解压后约 900 MB)', 'Downloading .NET SDK 10… (about 287 MB, about 900 MB unpacked)', 'Hämtar .NET SDK 10 … (ungefär 287 MB, ungefär 900 MB uppackat)', '.NET SDK 10 wird geladen … (etwa 287 MB, entpackt etwa 900 MB)'),
'dep.dotnet.done': ('.NET SDK 已安装:%@', '.NET SDK installed: %@', '.NET SDK installerat: %@', '.NET SDK installiert: %@'),
'dep.phase.download': ('下载', 'Download', 'Hämta', 'Download'),
diff --git a/frontend/Sources/NSPortBuilder/ContentView.swift b/frontend/Sources/NSPortBuilder/ContentView.swift
index d4f5d805..a45f5b94 100644
--- a/frontend/Sources/NSPortBuilder/ContentView.swift
+++ b/frontend/Sources/NSPortBuilder/ContentView.swift
@@ -2632,9 +2632,9 @@ final class BuildModel: ObservableObject {
}
/// Where the build looks for `dotnet`, in its order: build_ipa_from_nsp.py puts TOOL_PATHS (/opt/homebrew/bin,
- /// /usr/local/bin, /usr/local/share/dotnet, ~/.dotnet) in front of PATH, so `dotnet build` runs the first of these
- /// that exists. Checking ~/.dotnet first said .NET was fine on a Mac whose /usr/local/share/dotnet held an Intel
- /// .NET 7, while every build ran that one and stopped at NETSDK1045.
+ /// /usr/local/bin, /usr/local/share/dotnet, ~/.dotnet) in front of PATH, then the first of these that lists an SDK 10
+ /// in front of the rest (the engine patch nsp-dotnet-sdk10-first). Before that patch, every build on a Mac whose
+ /// /usr/local/share/dotnet held an Intel .NET 7 ran that one and stopped at NETSDK1045.
nonisolated static func dotnetCandidates(home: String = NSHomeDirectory()) -> [String] {
["/opt/homebrew/bin/dotnet", "/usr/local/bin/dotnet", "/usr/local/share/dotnet/dotnet", home + "/.dotnet/dotnet"]
}
@@ -2659,34 +2659,12 @@ final class BuildModel: ObservableObject {
return p.terminationStatus == 0 && hasSDK10(out)
}
- /// The dotnet the build runs, and whether it has an SDK 10 (an SDK, not just a runtime: the extractor is built).
- nonisolated static func findDotnet() -> (path: String, ok: Bool) {
- guard let d = firstExisting(dotnetCandidates()) else { return ("dotnet", false) }
- return (d, dotnetHasSDK10(d))
- }
-
- /// The .NET row's action: dotnet-install.sh into ~/.dotnet unless it already has an SDK 10, then, when another
- /// dotnet comes first for the build (`first`), a link to ~/.dotnet's in /usr/local/bin, which the build tries
- /// before /usr/local/share/dotnet.
- nonisolated static func dotnetInstallCommand(first: String?, home: String = NSHomeDirectory()) -> [String] {
- let own = home + "/.dotnet/dotnet"
- var script = "if ! \"$HOME/.dotnet/dotnet\" --list-sdks 2>/dev/null | grep -Eq '^[1-9][0-9]+\\.'; then "
- + "curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/di.sh && chmod +x /tmp/di.sh && /tmp/di.sh --channel 10.0 --install-dir $HOME/.dotnet; fi"
- if let first, first != own, first != "/opt/homebrew/bin/dotnet" {
- script += " && mkdir -p /usr/local/bin && ln -sf \"$HOME/.dotnet/dotnet\" /usr/local/bin/dotnet"
- }
- return ["/bin/bash", "-c", script]
- }
-
- /// The .NET row. `first` is the dotnet the build runs (nil: none), `ok` whether it has an SDK 10, `usable` a dotnet behind it
- /// that has one. Another dotnet ahead of a good one keeps the row from being ready, and Fix puts the good one in front.
- nonisolated static func dotnetDep(first: String?, ok: Bool, usable: String?, home: String = NSHomeDirectory()) -> Dep {
- let shadowed = ok ? nil : first
- var detail = "dep.dotnet.missing", action = ""
- if ok { detail = first ?? "" }
- else if let shadowed, let usable { detail = "dep.dotnet.shadowed:\(shadowed):\(usable)"; action = "dep.xcode.fix" }
- return Dep(id: "dotnet", name: "dep.dotnet", hint: "dep.dotnet.hint", present: ok, detail: detail, actionLabel: action,
- installCmd: dotnetInstallCommand(first: shadowed, home: home))
+ /// The dotnet the build runs and whether it has an SDK 10 (an SDK, not just a runtime: the extractor is built): the first
+ /// candidate that lists one, else the first that exists.
+ nonisolated static func findDotnet(_ cands: [String] = dotnetCandidates()) -> (path: String, ok: Bool) {
+ let found = cands.filter { firstExisting([$0]) != nil }
+ if let d = found.first(where: dotnetHasSDK10) { return (d, true) }
+ return (found.first ?? "dotnet", false)
}
/// Whether the selected developer directory exists (`xcode-select -p`), which is the same
@@ -2853,10 +2831,10 @@ final class BuildModel: ObservableObject {
brew: firstExisting(["/opt/homebrew/bin/brew", "/usr/local/bin/brew"]))
let (dn, dnOK) = findDotnet()
- let found = FileManager.default.isExecutableFile(atPath: dn)
- // A good dotnet behind the one the build runs
- let usable = found && !dnOK ? dotnetCandidates().drop { $0 != dn }.dropFirst().first { firstExisting([$0]) != nil && dotnetHasSDK10($0) } : nil
- out.append(dotnetDep(first: found ? dn : nil, ok: dnOK, usable: usable))
+ out.append(Dep(id: "dotnet", name: "dep.dotnet", hint: "dep.dotnet.hint",
+ present: dnOK, detail: dnOK ? dn : "dep.dotnet.missing",
+ installCmd: ["/bin/bash", "-c",
+ "curl -sSL https://dot.net/v1/dotnet-install.sh -o /tmp/di.sh && chmod +x /tmp/di.sh && /tmp/di.sh --channel 10.0 --install-dir $HOME/.dotnet"]))
let (py, pyOK) = findPython()
// A too-old interpreter is a different problem from a missing package: say which one it is,
diff --git a/frontend/Sources/NSPortBuilder/Localization.swift b/frontend/Sources/NSPortBuilder/Localization.swift
index 1467027a..a18c1436 100644
--- a/frontend/Sources/NSPortBuilder/Localization.swift
+++ b/frontend/Sources/NSPortBuilder/Localization.swift
@@ -824,7 +824,6 @@ enum L10n {
"dep.dotnet": (".NET SDK 10", ".NET SDK 10"),
"dep.dotnet.hint": ("dotnet-install.sh 装到 ~/.dotnet", "dotnet-install.sh into ~/.dotnet"),
"dep.dotnet.missing": ("没找到带 SDK 10 的 dotnet", "no dotnet with SDK 10 found"),
- "dep.dotnet.shadowed": ("构建会先用 %@,它没有 SDK 10。点「修复」把 %@ 放到它前面", "the build runs %@, which has no SDK 10. Fix puts %@ in front of it"),
"dep.dotnet.downloading": ("正在下载 .NET SDK 10…(约 287 MB,解压后约 900 MB)", "Downloading .NET SDK 10… (about 287 MB, about 900 MB unpacked)"),
"dep.dotnet.done": (".NET SDK 已安装:%@", ".NET SDK installed: %@"),
"dep.phase.download": ("下载", "Download"),
@@ -1660,7 +1659,6 @@ enum L10n {
"dep.dotnet": ".NET SDK 10",
"dep.dotnet.hint": "dotnet-install.sh till ~/.dotnet",
"dep.dotnet.missing": "ingen dotnet med SDK 10 hittades",
- "dep.dotnet.shadowed": "bygget kör %@, som saknar SDK 10. Åtgärda lägger %@ före den",
"dep.dotnet.downloading": "Hämtar .NET SDK 10 … (ungefär 287 MB, ungefär 900 MB uppackat)",
"dep.dotnet.done": ".NET SDK installerat: %@",
"dep.phase.download": "Hämta",
@@ -2586,7 +2584,6 @@ enum L10n {
"dep.dotnet": ".NET SDK 10",
"dep.dotnet.hint": "dotnet-install.sh nach ~/.dotnet",
"dep.dotnet.missing": "kein dotnet mit SDK 10 gefunden",
- "dep.dotnet.shadowed": "der Build nutzt %@, das kein SDK 10 hat. Beheben stellt %@ davor",
"dep.dotnet.downloading": ".NET SDK 10 wird geladen … (etwa 287 MB, entpackt etwa 900 MB)",
"dep.dotnet.done": ".NET SDK installiert: %@",
"dep.phase.download": "Download",
diff --git a/frontend/Tests/NSPortBuilderTests/DotnetDetectionTests.swift b/frontend/Tests/NSPortBuilderTests/DotnetDetectionTests.swift
index ce13ea73..7b9f8c1e 100644
--- a/frontend/Tests/NSPortBuilderTests/DotnetDetectionTests.swift
+++ b/frontend/Tests/NSPortBuilderTests/DotnetDetectionTests.swift
@@ -1,8 +1,7 @@
import XCTest
-import SwiftUI
@testable import NSPortBuilder
-/// The .NET row checks the dotnet the build runs, in the build's own order, and wants an SDK 10 from it.
+/// The .NET row looks for dotnet in the build's order and is ready with the first that lists an SDK 10, the one the build puts in front.
final class DotnetDetectionTests: XCTestCase {
func testTheBuildsOrder() {
// build_ipa_from_nsp.py's TOOL_PATHS: Homebrew, /usr/local/bin, the installer's folder, then ~/.dotnet
@@ -18,87 +17,30 @@ final class DotnetDetectionTests: XCTestCase {
XCTAssertTrue(BuildModel.hasSDK10("11.0.100-preview.1 [/b/sdk]"))
}
- func testFixLinksOnlyWhenAnotherDotnetComesFirst() {
- let plain = BuildModel.dotnetInstallCommand(first: nil, home: "/Users/p").last!
- XCTAssertTrue(plain.contains("--install-dir $HOME/.dotnet"))
- XCTAssertFalse(plain.contains("ln -sf"))
- let own = BuildModel.dotnetInstallCommand(first: "/Users/p/.dotnet/dotnet", home: "/Users/p").last!
- XCTAssertFalse(own.contains("ln -sf"))
- let shadowed = BuildModel.dotnetInstallCommand(first: "/usr/local/share/dotnet/dotnet", home: "/Users/p").last!
- XCTAssertTrue(shadowed.hasSuffix("ln -sf \"$HOME/.dotnet/dotnet\" /usr/local/bin/dotnet"))
- // a link in /usr/local/bin cannot get ahead of Homebrew's own
- XCTAssertFalse(BuildModel.dotnetInstallCommand(first: "/opt/homebrew/bin/dotnet", home: "/Users/p").last!.contains("ln -sf"))
- }
-
- func testTheRow() {
- let shadowed = BuildModel.dotnetDep(first: "/usr/local/share/dotnet/dotnet", ok: false, usable: "/Users/p/.dotnet/dotnet", home: "/Users/p")
- XCTAssertFalse(shadowed.present)
- XCTAssertEqual(shadowed.detail, "dep.dotnet.shadowed:/usr/local/share/dotnet/dotnet:/Users/p/.dotnet/dotnet")
- XCTAssertEqual(shadowed.actionLabel, "dep.xcode.fix")
- XCTAssertTrue(shadowed.installCmd.last!.contains("ln -sf"))
-
- let ready = BuildModel.dotnetDep(first: "/usr/local/bin/dotnet", ok: true, usable: nil, home: "/Users/p")
- XCTAssertTrue(ready.present)
- XCTAssertEqual(ready.detail, "/usr/local/bin/dotnet")
-
- let none = BuildModel.dotnetDep(first: nil, ok: false, usable: nil, home: "/Users/p")
- XCTAssertEqual(none.detail, "dep.dotnet.missing")
- XCTAssertEqual(none.actionLabel, "")
- XCTAssertFalse(none.installCmd.last!.contains("ln -sf"))
-
- // an old SDK in front and none anywhere else: Install brings .NET 10 into ~/.dotnet and puts it in front
- let old = BuildModel.dotnetDep(first: "/usr/local/share/dotnet/dotnet", ok: false, usable: nil, home: "/Users/p")
- XCTAssertEqual(old.detail, "dep.dotnet.missing")
- XCTAssertEqual(old.actionLabel, "")
- XCTAssertTrue(old.installCmd.last!.contains("ln -sf"))
- }
-
- @MainActor func testTheShadowedRowNamesBothPaths() {
- let model = BuildModel()
- model.lang = .en
- XCTAssertEqual(model.depDetail(BuildModel.dotnetDep(first: "/usr/local/share/dotnet/dotnet", ok: false, usable: "/opt/x/dotnet")),
- "the build runs /usr/local/share/dotnet/dotnet, which has no SDK 10. Fix puts /opt/x/dotnet in front of it")
- }
-
- /// Opt-in native rendering for pull request screenshots (NX_LAUNCHER_CAPTURE_DIR): Settings with the .NET row of a Mac whose
- /// /usr/local/share/dotnet holds an older .NET in front of the .NET 10 in ~/.dotnet, and the same row once Fix has run.
- @MainActor func testRenderTheDotnetRowForVisualQA() throws {
- guard let directory = ProcessInfo.processInfo.environment["NX_LAUNCHER_CAPTURE_DIR"] else { throw XCTSkip("Set NX_LAUNCHER_CAPTURE_DIR to capture native views") }
- let output = URL(fileURLWithPath: directory)
- let temporary = FileManager.default.temporaryDirectory.appendingPathComponent("dotnet-capture-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: output, withIntermediateDirectories: true)
- try FileManager.default.createDirectory(at: temporary, withIntermediateDirectories: true)
- defer { try? FileManager.default.removeItem(at: temporary) }
- NSApplication.shared.setActivationPolicy(.accessory)
- let oldRepo = UserDefaults.standard.object(forKey: "repoPath"), oldExpanded = UserDefaults.standard.object(forKey: "depsExpanded")
- defer {
- UserDefaults.standard.set(oldRepo, forKey: "repoPath")
- UserDefaults.standard.set(oldExpanded, forKey: "depsExpanded")
+ func testTheFirstWithAnSDK10() throws {
+ let dir = FileManager.default.temporaryDirectory.appendingPathComponent("dotnet-\(UUID().uuidString)")
+ defer { try? FileManager.default.removeItem(at: dir) }
+ func dotnet(_ name: String, _ sdks: String, exit code: Int = 0) throws -> String {
+ let folder = dir.appendingPathComponent(name)
+ try FileManager.default.createDirectory(at: folder, withIntermediateDirectories: true)
+ let file = folder.appendingPathComponent("dotnet")
+ try "#!/bin/sh\nprintf '\(sdks)'\nexit \(code)\n".write(to: file, atomically: true, encoding: .utf8)
+ try FileManager.default.setAttributes([.posixPermissions: 0o755], ofItemAtPath: file.path)
+ return file.path
}
- let model = BuildModel()
- model.repoPath = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent().path
- model.lang = CaptureLanguage.current(.en)
- model.depsChecked = true
- model.depsExpanded = true
- let rows = [BuildModel.Dep(id: "xcode", name: "dep.xcode", hint: "dep.xcode.hint", present: true, installCmd: []),
- BuildModel.Dep(id: "metal", name: "dep.metal", hint: "dep.metal.hint", present: true, installCmd: [])]
- let python = BuildModel.Dep(id: "python", name: "dep.python", hint: "dep.python.hint", present: true, detail: "dep.bundled", installCmd: [])
- let library = GameLibrary(file: temporary.appendingPathComponent("library.json"))
- for (name, dotnet) in [("dotnet-shadowed", BuildModel.dotnetDep(first: "/usr/local/share/dotnet/dotnet", ok: false, usable: NSHomeDirectory() + "/.dotnet/dotnet")),
- ("dotnet-fixed", BuildModel.dotnetDep(first: "/usr/local/bin/dotnet", ok: true, usable: nil))] {
- model.deps = rows + [dotnet, python]
- let host = NSHostingView(rootView: ContentView(model: model, library: library, initialPage: .settings, performStartupChecks: false))
- let window = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 1440, height: 1400), styleMask: [.titled, .closable, .resizable],
- backing: .buffered, defer: false)
- window.contentView = host
- window.orderFront(nil)
- RunLoop.main.run(until: Date().addingTimeInterval(0.5))
- host.layoutSubtreeIfNeeded()
- let rep = try XCTUnwrap(host.bitmapImageRepForCachingDisplay(in: host.bounds))
- host.cacheDisplay(in: host.bounds, to: rep)
- try XCTUnwrap(rep.representation(using: .png, properties: [:]))
- .write(to: output.appendingPathComponent("\(name)-\(model.lang.rawValue).png"))
- window.orderOut(nil)
+ func pick(_ cands: [String]) -> String {
+ let r = BuildModel.findDotnet(cands)
+ return (r.ok ? "ready " : "missing ") + r.path
}
+ let old = try dotnet("share", "7.0.402 [/s/sdk]\\n"), home = try dotnet("home", "9.0.100 [/h/sdk]\\n10.0.403 [/h/sdk]\\n")
+ let broken = try dotnet("broken", "10.0.403 [/b/sdk]\\n", exit: 1), absent = dir.appendingPathComponent("none/dotnet").path
+
+ // an Intel .NET 7 in /usr/local/share/dotnet before the .NET 10 in ~/.dotnet: the build puts the second in front
+ XCTAssertEqual(pick([absent, old, home]), "ready " + home)
+ XCTAssertEqual(pick([home, old]), "ready " + home)
+ XCTAssertEqual(pick([broken, home]), "ready " + home)
+ // no SDK 10 anywhere: Install, as with no dotnet at all
+ XCTAssertEqual(pick([absent, old]), "missing " + old)
+ XCTAssertEqual(pick([absent]), "missing dotnet")
}
}
diff --git a/patches/0054-nsp-dotnet-sdk10-first.patch b/patches/0054-nsp-dotnet-sdk10-first.patch
new file mode 100644
index 00000000..21227f8b
--- /dev/null
+++ b/patches/0054-nsp-dotnet-sdk10-first.patch
@@ -0,0 +1,117 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Aaron Oliphant <[email protected]>
+Date: Sat, 31 Oct 2026 15:21:44 -0400
+Subject: [PATCH] NSP script: the first dotnet with an SDK 10 goes in front of
+ PATH
+
+TOOL_PATHS looks in /usr/local/share/dotnet before ~/.dotnet. On a Mac where an installer left an older .NET there (an Intel
+.NET 7, run under Rosetta) and dotnet-install.sh put .NET 10 into ~/.dotnet, every build ran the old one and stopped at
+nx_extract with NETSDK1045. dotnet_sdk10_first moves the directory of the first dotnet that lists an SDK 10 or newer in
+front, before configure_dotnet reads the runtime root from it. PATH stays as it is when the first dotnet has an SDK 10 or
+none has one, so nothing else changes order.
+
+Upstream-Status: pending
+Reason: An older .NET in /usr/local/share/dotnet comes before the .NET 10 in ~/.dotnet in TOOL_PATHS, and the build stops with NETSDK1045
+Issue: LNPANDY/NX2Apple#342
+
+Co-Authored-By: Claude Opus 5.5 <[email protected]>
+
+---
+ dm/tools/tests/test_nsp_dotnet.py | 42 +++++++++++++++++++++++++++++++
+ scripts/build_ipa_from_nsp.py | 18 +++++++++++++
+ 2 files changed, 60 insertions(+)
+
+diff --git a/dm/tools/tests/test_nsp_dotnet.py b/dm/tools/tests/test_nsp_dotnet.py
+index f81a641..80cda9e 100644
+--- a/dm/tools/tests/test_nsp_dotnet.py
++++ b/dm/tools/tests/test_nsp_dotnet.py
+@@ -6,6 +6,7 @@ import os
+ from pathlib import Path
+ import subprocess
+ import sys
++import tempfile
+ import unittest
+ from unittest import mock
+
+@@ -67,4 +68,45 @@ class Dotnet(unittest.TestCase):
+ self.assertNotIn('DOTNET_ROOT', os.environ)
+
+
++class Sdk10First(unittest.TestCase):
++ """An older .NET earlier on PATH (an installer's /usr/local/share/dotnet before ~/.dotnet) gives way to the first dotnet with an SDK 10."""
++ def setUp(self):
++ t = tempfile.TemporaryDirectory(); self.addCleanup(t.cleanup); self.tmp = Path(t.name)
++ self.tools = str(self.tmp / 'tools'); os.mkdir(self.tools) # a PATH entry without dotnet
++
++ def dotnet(self, name, sdks, code=0):
++ d = self.tmp / name; d.mkdir()
++ (d / 'dotnet').write_text(f'#!/bin/sh\nprintf "{sdks}"\nexit {code}\n'); (d / 'dotnet').chmod(0o755)
++ return str(d)
++
++ def path_after(self, *dirs):
++ env = {'PATH': os.pathsep.join(dirs)}
++ with mock.patch.object(nsp, 'say') as say: nsp.dotnet_sdk10_first(env)
++ self.said = say.call_args
++ return env['PATH'].split(os.pathsep)
++
++ def test_older_sdk_in_front_gives_way(self):
++ old, home = self.dotnet('share', '7.0.402 [/s/sdk]\\n'), self.dotnet('home', '9.0.100 [/h/sdk]\\n10.0.403 [/h/sdk]\\n')
++ self.assertEqual(self.path_after(self.tools, old, home, '/usr/bin'), [home, self.tools, old, '/usr/bin'])
++ self.assertIn(old, self.said.args[0])
++
++ def test_preview_counts(self):
++ old, new = self.dotnet('share', '8.0.318 [/s/sdk]\\n'), self.dotnet('home', '11.0.100-preview.1 [/h/sdk]\\n')
++ self.assertEqual(self.path_after(old, new), [new, old])
++
++ def test_first_with_sdk10_keeps_the_order(self):
++ local, home = self.dotnet('local', '10.0.403 [/l/sdk]\\n'), self.dotnet('home', '10.0.100 [/h/sdk]\\n')
++ dirs = [self.tools, local, home]
++ self.assertEqual(self.path_after(*dirs), dirs)
++ self.assertIsNone(self.said)
++
++ def test_no_sdk10_keeps_the_order(self):
++ dirs = [self.dotnet('share', '7.0.402 [/s/sdk]\\n'), self.dotnet('home', '8.0.318 [/h/sdk]\\n9.0.100 [/h/sdk]\\n')]
++ self.assertEqual(self.path_after(*dirs), dirs)
++
++ def test_failing_dotnet_is_skipped(self):
++ broken, home = self.dotnet('broken', '', code=1), self.dotnet('home', '10.0.403 [/h/sdk]\\n')
++ self.assertEqual(self.path_after(broken, home, broken), [home, broken, broken])
++
++
+ if __name__ == '__main__': unittest.main()
+diff --git a/scripts/build_ipa_from_nsp.py b/scripts/build_ipa_from_nsp.py
+index a287425..18392e4 100755
+--- a/scripts/build_ipa_from_nsp.py
++++ b/scripts/build_ipa_from_nsp.py
+@@ -417,6 +417,23 @@ def configure_dotnet(env):
+ return
+
+
++def dotnet_sdk10_first(env):
++ """Put the first dotnet on PATH that lists an SDK 10 or newer in front. TOOL_PATHS looks in /usr/local/share/dotnet before ~/.dotnet, so an
++ older .NET left there by an installer would build nx_extract and stop with NETSDK1045 while the .NET 10 of dotnet-install.sh sits in ~/.dotnet.
++ PATH stays as it is when the first dotnet has an SDK 10 or none has one."""
++ dirs = env['PATH'].split(os.pathsep)
++ found = list(dict.fromkeys(d for d in dirs if d and shutil.which('dotnet', path=d)))
++ for i, d in enumerate(found):
++ try:
++ out = subprocess.run([shutil.which('dotnet', path=d), '--list-sdks'], env=env, capture_output=True, text=True, timeout=30).stdout
++ except (OSError, subprocess.SubprocessError): continue
++ if any(int(v) >= 10 for v in re.findall(r'^(\d+)\.', out, re.M)):
++ if i:
++ env['PATH'] = os.pathsep.join([d] + [x for x in dirs if x != d])
++ say(f'dotnet: {d}, the first with an SDK 10 ({found[0]} comes before it and has none)')
++ return
++
++
+ # ---- NSP identification ----
+ def pfs0_names(path): # NSP = PFS0: list the file names inside
+ with open(path, 'rb') as f:
+@@ -2368,6 +2385,7 @@ def main(args=None):
+ # who wants telemetry on keeps it.
+ env.setdefault('DOTNET_CLI_TELEMETRY_OPTOUT', '1')
+ env.setdefault('DOTNET_NOLOGO', '1')
++ dotnet_sdk10_first(env) # before configure_dotnet, which takes the runtime root from the dotnet PATH finds first
+ configure_dotnet(env)
+ xlate_bin = repo / 'dm/gfx/tools/dmsh_xlate_bin/dmsh_xlate' # the fork's check of the root configure_dotnet chose (fork commit d0ed53df; the fork patch nsp-dotnet-root-verify)
+ def xlate_answers(root):
diff --git a/patches/series b/patches/series
index e3651beb..45654716 100644
--- a/patches/series
+++ b/patches/series
@@ -35,3 +35,4 @@
0050-route-c-shell.patch
0051-nsp-shell-framework.patch
0053-runtime-profile-every-site.patch
+0054-nsp-dotnet-sdk10-first.patch