dotnet-maui-doctor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese.NET MAUI Doctor
.NET MAUI Doctor
Validate and fix .NET MAUI development environments. All version requirements are discovered dynamically from NuGet APIs — never hardcode versions.
验证并修复.NET MAUI开发环境。所有版本要求均通过NuGet API动态获取——绝不硬编码版本号。
When to Use
适用场景
- Setting up a new .NET MAUI development environment
- Build errors mentioning missing SDKs, workloads, JDK, or Android components
- Errors like "Android SDK not found", "Java version", or "Xcode not found"
- Verifying environment health after SDK or OS updates
- 搭建新的.NET MAUI开发环境
- 出现提及缺失SDK、工作负载、JDK或Android组件的构建错误
- 出现"Android SDK未找到"、"Java版本"或"Xcode未找到"等错误
- SDK或系统更新后验证环境健康状态
When Not to Use
不适用场景
- Non-MAUI .NET projects (use standard .NET SDK troubleshooting instead)
- Xamarin.Forms apps (different toolchain and workload requirements)
- Runtime app crashes unrelated to environment setup
- App store publishing or signing issues
- IDE-specific issues (Visual Studio or VS Code configuration)
- 非MAUI的.NET项目(请使用标准.NET SDK故障排查方法)
- Xamarin.Forms应用(工具链和工作负载要求不同)
- 与环境设置无关的运行时应用崩溃
- 应用商店发布或签名问题
- IDE特定问题(Visual Studio或VS Code配置问题)
Important: .NET Version Currency
重要提示:.NET版本时效性
Your training data may be outdated regarding .NET versions. .NET ships new major releases annually (November). Always check the releases-index.json (Task 2) to discover the latest active major release — do not assume your training data reflects the current version. For example, if you know about .NET 9.0 but the releases index shows .NET 10.0 as active, use .NET 10.0.
你的训练数据可能关于.NET版本的内容已过时。.NET每年11月发布新的主版本。请始终查看releases-index.json(任务2)以了解最新的活跃主版本——不要假设训练数据反映当前版本。例如,如果你知道.NET 9.0,但版本索引显示.NET 10.0为活跃版本,请使用.NET 10.0。
Inputs
输入要求
- A development machine running macOS, Windows, or Linux
- Shell access (Bash on macOS/Linux, PowerShell on Windows)
- Internet access for NuGet API queries and SDK downloads
- Admin/sudo access may be required for installing SDKs and workloads
- Bash prerequisites: ,
curl, andjq(macOS/Linux)unzip - PowerShell prerequisites: and
Invoke-RestMethod(built-in on Windows)System.IO.Compression
- 运行macOS、Windows或Linux的开发机器
- Shell访问权限(macOS/Linux使用Bash,Windows使用PowerShell)
- 可访问互联网,用于NuGet API查询和SDK下载
- 安装SDK和工作负载可能需要管理员/ sudo权限
- Bash前置依赖:、
curl和jq(macOS/Linux)unzip - PowerShell前置依赖:和
Invoke-RestMethod(Windows系统内置)System.IO.Compression
Behavior
行为规则
- Run through ALL tasks autonomously
- Re-validate after each fix
- Iterate until complete or no further actions possible
- After detecting platform (Task 1), load only the matching platform-specific references
- 自动执行所有任务
- 每次修复后重新验证
- 循环执行,直到完成或无法进行进一步操作
- 检测平台(任务1)后,仅加载匹配的平台特定参考文档
Workflow
工作流程
Task 1: Detect Environment
任务1:检测环境
bash
undefinedbash
undefinedmacOS
macOS
sw_vers && uname -m
sw_vers && uname -m
Windows
Windows
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
Linux
Linux
cat /etc/os-release && uname -m
After detection, load the matching platform references:
- **macOS**: `references/platform-requirements-macos.md`, `references/installation-commands-macos.md`, `references/troubleshooting-macos.md`
- **Windows**: `references/platform-requirements-windows.md`, `references/installation-commands-windows.md`, `references/troubleshooting-windows.md`
- **Linux**: `references/platform-requirements-linux.md`cat /etc/os-release && uname -m
检测完成后,加载匹配的平台参考文档:
- **macOS**:`references/platform-requirements-macos.md`、`references/installation-commands-macos.md`、`references/troubleshooting-macos.md`
- **Windows**:`references/platform-requirements-windows.md`、`references/installation-commands-windows.md`、`references/troubleshooting-windows.md`
- **Linux**:`references/platform-requirements-linux.md`Task 2: Check .NET SDK
任务2:检查.NET SDK
bash
dotnet --infoCompare installed vs from https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json where is .
latest-sdksupport-phase"active"Task 3: Check MAUI Workloads
任务3:检查MAUI工作负载
| Workload | macOS | Windows | Linux |
|---|---|---|---|
| Required | Required | ❌ Use |
| Alias | Alias | Required |
| Required | Required | Required |
| Required | Optional | N/A |
| 工作负载 | macOS | Windows | Linux |
|---|---|---|---|
| 必填 | 必填 | ❌ 请使用 |
| 别名 | 别名 | 必填 |
| 必填 | 必填 | 必填 |
| 必填 | 可选 | 不适用 |
Task 4: Discover Requirements from NuGet
任务4:从NuGet获取依赖要求
See for complete process.
references/workload-dependencies-discovery.mdQuery NuGet for workload manifest → extract → get:
WorkloadDependencies.json- range and
jdk.versionjdk.recommendedVersion - ,
androidsdk.packages,buildToolsVersionapiLevel - range
xcode.version
完整流程请查看。
references/workload-dependencies-discovery.md查询NuGet获取工作负载清单 → 提取 → 获取以下信息:
WorkloadDependencies.json- 范围和
jdk.versionjdk.recommendedVersion - 、
androidsdk.packages、buildToolsVersionapiLevel - 范围
xcode.version
Task 5: Validate Java JDK
任务5:验证Java JDK
Only Microsoft OpenJDK supported. Verify output contains "Microsoft". See for detection paths.
java -versionreferences/microsoft-openjdk.mdUse the JDK version recommended by WorkloadDependencies.json (), ensuring it satisfies thejdk.recommendedVersionrange. Do not hardcode JDK versions.jdk.version
JAVA_HOME is NOT required. .NET MAUI tools auto-detect Microsoft OpenJDK installations from known paths. Do not tell users to set JAVA_HOME — it is unnecessary and risks pointing to a non-Microsoft JDK.
| JAVA_HOME state | OK? | Action |
|---|---|---|
| Not set | ✅ | None needed — auto-detection works |
| Set to Microsoft JDK | ✅ | None needed |
| Set to non-Microsoft JDK | ⚠️ | Report as anomaly — let user decide to unset or redirect |
仅支持Microsoft OpenJDK。验证输出中包含"Microsoft"。检测路径请查看。
java -versionreferences/microsoft-openjdk.md请使用WorkloadDependencies.json推荐的JDK版本(),确保其满足jdk.recommendedVersion范围要求。请勿硬编码JDK版本。jdk.version
无需设置JAVA_HOME。.NET MAUI工具会从已知路径自动检测Microsoft OpenJDK安装。请勿告知用户设置JAVA_HOME——这毫无必要,还可能指向非Microsoft JDK。
| JAVA_HOME状态 | 是否正常? | 操作 |
|---|---|---|
| 未设置 | ✅ | 无需操作——自动检测生效 |
| 已设置为Microsoft JDK | ✅ | 无需操作 |
| 已设置为非Microsoft JDK | ⚠️ | 报告异常——由用户决定是否取消设置或重定向 |
Task 6: Validate Android SDK
任务6:验证Android SDK
Check packages from , , (Task 4). See for sdkmanager commands.
androidsdk.packagesbuildToolsVersionapiLevelreferences/installation-commands.md根据任务4获取的、、检查对应包。安装命令请查看中的sdkmanager命令。
androidsdk.packagesbuildToolsVersionapiLevelreferences/installation-commands.mdTask 7: Validate Xcode (macOS Only)
任务7:验证Xcode(仅macOS)
bash
xcodebuild -versionCompare against range from Task 4. See .
xcode.versionreferences/installation-commands-macos.mdbash
xcodebuild -version与任务4获取的范围进行对比。安装命令请查看。
xcode.versionreferences/installation-commands-macos.mdTask 8: Validate Windows SDK (Windows Only)
任务8:验证Windows SDK(仅Windows)
The Windows SDK is typically installed as part of the .NET MAUI workload or Visual Studio. See .
references/installation-commands-windows.mdWindows SDK通常随.NET MAUI工作负载或Visual Studio一同安装。安装命令请查看。
references/installation-commands-windows.mdTask 9: Remediation
任务9:修复操作
See for all commands.
references/installation-commands.mdKey rules:
- Workloads: Always use flag. Never use
--versionorworkload update.workload repair - JDK: Only install Microsoft OpenJDK. Do not set JAVA_HOME (auto-detected).
- Android SDK: Use (from Android SDK command-line tools). On Windows use
sdkmanager.sdkmanager.bat
所有命令请查看。
references/installation-commands.md核心规则:
- 工作负载:始终使用参数。绝不要使用
--version或workload update命令。workload repair - JDK:仅安装Microsoft OpenJDK。无需设置JAVA_HOME(自动检测)。
- Android SDK:使用(来自Android SDK命令行工具)。Windows系统请使用
sdkmanager。sdkmanager.bat
Task 10: Re-validate
任务10:重新验证
After each fix, re-run the relevant validation task. Iterate until all checks pass.
每次修复后,重新运行对应的验证任务。循环执行直到所有检查通过。
Validation
验证标准
A successful run produces:
- .NET SDK installed and matches an active release
- All required workloads installed with consistent versions
- Microsoft OpenJDK detected (contains "Microsoft")
java -version - All required Android SDK packages installed (per WorkloadDependencies.json)
- Xcode version in supported range (macOS only)
- Windows SDK detected (Windows only)
运行成功的标志:
- .NET SDK已安装且匹配活跃版本
- 所有必填工作负载已安装且版本一致
- 检测到Microsoft OpenJDK(输出包含"Microsoft")
java -version - 所有必填Android SDK包已安装(符合WorkloadDependencies.json要求)
- Xcode版本在支持范围内(仅macOS)
- 检测到Windows SDK(仅Windows)
Build Verification (Recommended)
构建验证(推荐)
After all checks pass, create and build a test project to confirm the environment actually works:
bash
TEMP_DIR=$(mktemp -d)
dotnet new maui -o "$TEMP_DIR/MauiTest"
dotnet build "$TEMP_DIR/MauiTest"
rm -rf "$TEMP_DIR"On Windows, use or for the temp directory.
$env:TEMPNew-TemporaryFileIf the build succeeds, the environment is verified. If it fails, use the error output to diagnose remaining issues.
所有检查通过后,创建并构建测试项目以确认环境可正常工作:
bash
TEMP_DIR=$(mktemp -d)
dotnet new maui -o "$TEMP_DIR/MauiTest"
dotnet build "$TEMP_DIR/MauiTest"
rm -rf "$TEMP_DIR"Windows系统请使用或创建临时目录。
$env:TEMPNew-TemporaryFile如果构建成功,则环境验证通过。如果失败,请使用错误输出诊断剩余问题。
Run Verification (Optional — Ask User First)
运行验证(可选——需先询问用户)
After a successful build, ask the user if they want to launch the app on a target platform to verify end-to-end:
bash
undefined构建成功后,询问用户是否要在目标平台启动应用以验证端到端流程:
bash
undefinedReplace net10.0 with the current major .NET version
将net10.0替换为当前的.NET主版本
dotnet build -t:Run -f net10.0-android
dotnet build -t:Run -f net10.0-ios # macOS only
dotnet build -t:Run -f net10.0-maccatalyst # macOS only
dotnet build -t:Run -f net10.0-windows # Windows only
Only run the target frameworks relevant to the user's platform and intent. This step deploys to an emulator/simulator/device, so confirm with the user before proceeding.dotnet build -t:Run -f net10.0-android
dotnet build -t:Run -f net10.0-ios # 仅macOS
dotnet build -t:Run -f net10.0-maccatalyst # 仅macOS
dotnet build -t:Run -f net10.0-windows # 仅Windows
仅运行与用户平台和需求相关的目标框架。此步骤会将应用部署到模拟器/仿真器/设备,因此请先征得用户同意再执行。Common Pitfalls
常见误区
- vs
mauiworkload: On Linux, themaui-androidmeta-workload is not available — usemauiinstead. On macOS/Windows,maui-androidinstalls all platform workloads.maui - /
workload update: Never use these commands. Always install workloads with an explicitworkload repairflag to ensure version consistency.--version - Non-Microsoft JDK: Only Microsoft OpenJDK is supported. Other distributions (Oracle, Adoptium, Azul) will cause build failures even if the version is correct.
- Unnecessary JAVA_HOME: Do not set JAVA_HOME. MAUI auto-detects JDK from known install paths. If JAVA_HOME is set to a non-Microsoft JDK (e.g., Temurin), report this as an anomaly — it may override auto-detection and cause failures. Let the user decide whether to unset it.
- Hardcoded versions: Never hardcode SDK, workload, or dependency versions. Always discover them dynamically from the NuGet APIs (see Task 4).
- Android SDK on Windows: Use
sdkmanager, notsdkmanager.bat, on Windows.sdkmanager - Stale training data: LLM training data may reference outdated .NET versions. Always check the releases-index.json to discover the current active release.
- 与
maui工作负载:Linux系统不提供maui-android元工作负载——请使用maui。macOS/Windows系统中,maui-android会安装所有平台工作负载。maui - /
workload update:绝不要使用这些命令。始终使用显式workload repair参数安装工作负载,以确保版本一致性。--version - 非Microsoft JDK:仅支持Microsoft OpenJDK。其他发行版(Oracle、Adoptium、Azul)即使版本正确也会导致构建失败。
- 不必要的JAVA_HOME:请勿设置JAVA_HOME。MAUI会从已知安装路径自动检测JDK。如果JAVA_HOME指向非Microsoft JDK(如Temurin),请将其报告为异常——这可能覆盖自动检测并导致失败。由用户决定是否取消设置。
- 硬编码版本:绝不要硬编码SDK、工作负载或依赖版本。始终通过NuGet API动态获取(见任务4)。
- Windows系统的Android SDK :Windows系统请使用
sdkmanager,而非sdkmanager.bat。sdkmanager - 过时的训练数据:大语言模型的训练数据可能引用过时的.NET版本。请始终查看releases-index.json以获取当前的活跃版本。
References
参考文档
- — NuGet API discovery process
references/workload-dependencies-discovery.md - — JDK detection paths, identification, JAVA_HOME
references/microsoft-openjdk.md - — .NET workloads, Android SDK (sdkmanager)
references/installation-commands.md - — Common errors and solutions
references/troubleshooting.md - — Platform-specific requirements
references/platform-requirements-{platform}.md - — Platform-specific install commands
references/installation-commands-{platform}.md - — Platform-specific troubleshooting
references/troubleshooting-{platform}.md
Official docs:
- — NuGet API获取流程
references/workload-dependencies-discovery.md - — JDK检测路径、识别方法、JAVA_HOME相关说明
references/microsoft-openjdk.md - — .NET工作负载、Android SDK(sdkmanager)安装命令
references/installation-commands.md - — 常见错误及解决方案
references/troubleshooting.md - — 平台特定要求
references/platform-requirements-{platform}.md - — 平台特定安装命令
references/installation-commands-{platform}.md - — 平台特定故障排查
references/troubleshooting-{platform}.md
官方文档: