AGENT SKILL

WinUI 3 开发环境配置

winui-setup

安装并验证 WinUI 3 的先决条件——.NET SDK 8.0.100+、WinApp CLI 0.7+ 以及开发者模式;识别 Native AOT 和 Windows Sandbox 的额外要求。当用户请求设置或修复工具链,或其他 WinUI 技能发现先决条件缺失或过时时使用。

License 许可
MIT
最近更新
2026-11-14
Stars
★ 1.4k
Forks
96

01 前言 Front Matter

name
winui-setup
description
Install and verify WinUI 3 prerequisites — .NET SDK 8.0.100+, WinApp CLI 0.7+, and Developer Mode; identify additional Native AOT and Windows Sandbox requirements. Use when the user asks to set up or repair the toolchain, or when another WinUI skill finds a missing or outdated prerequisite.

03 SKILL.md 正文

Purpose

Install and verify the prerequisites every other winui-* skill assumes. WinApp CLI 0.7 owns WinUI template discovery and installation through winapp new; do not install the template pack separately. The project's target framework may require a newer .NET SDK than the CLI's minimum.

[!IMPORTANT] Install per-user prerequisites (WinApp CLI) without asking, and tell the user what changed. Ask before anything that needs admin rights (UAC) or a large toolchain — the .NET SDK, Developer Mode, and Native AOT build tools. Windows Sandbox enablement is the user's to do.

This skill is idempotent: detect everything first, install or upgrade only what is needed, and print one final summary.

Steps

Detect everything

Run these checks together so the user sees the full state before anything changes:

$minimumDotNet = [version]'8.0.100'
$minimumWinApp = [version]'0.7.0'

# .NET SDK — project-mode winapp run requires SDK 8.0.100+
$dotnetSdks = @(& dotnet --list-sdks 2>$null) | ForEach-Object {
    $text = ($_ -replace ' \[.*$','').Trim()
    $parsed = $null
    if ([version]::TryParse(($text -split '-')[0], [ref]$parsed)) { $parsed }
}
$dotnetVersion = $dotnetSdks |
    Where-Object { $_ -ge $minimumDotNet } |
    Sort-Object -Descending |
    Select-Object -First 1
$dotnetOk = $null -ne $dotnetVersion

# WinApp CLI — require released 0.7+ for the migrated workflows
$winappCmd = Get-Command winapp -ErrorAction SilentlyContinue
$winappVersion = $null
$winappPrerelease = $false
if ($winappCmd) {
    foreach ($line in @(& winapp --version 2>$null)) {
        $match = [regex]::Match(
            [string]$line,
            '^\s*v?(?<version>\d+\.\d+\.\d+)(?:-(?<prerelease>[0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?\s*$'
        )
        if ($match.Success) {
            $parsed = $null
            if ([version]::TryParse($match.Groups['version'].Value, [ref]$parsed)) {
                $winappVersion = $parsed
                $winappPrerelease = $match.Groups['prerelease'].Success
            }
        }
    }
}
$winappOk = ($winappVersion -ge $minimumWinApp) -and -not $winappPrerelease

# Developer Mode
$devModeOk = ((Get-ItemProperty `
    -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock' `
    -Name AllowDevelopmentWithoutDevLicense -ErrorAction SilentlyContinue
).AllowDevelopmentWithoutDevLicense) -eq 1

Print a one-shot status table:

.NET SDK >= 8.0.100     [OK] found 10.0.100
WinApp CLI >= 0.7.0     [!] found 0.6.0 — will upgrade
Developer Mode          [X] disabled — needs admin to enable

Install what's missing

.NET SDK (ask first)

The SDK installer is machine-wide and triggers UAC. Ask the user first. When they agree and no SDK at or above 8.0.100 was found, install the recommended SDK:

winget install --id Microsoft.DotNet.SDK.10 --exact --silent --accept-package-agreements --accept-source-agreements

Do not install another SDK when one already satisfies both the CLI minimum and the requested project's target framework / global.json. The CLI's minimum does not let an 8.x SDK build a net10.0-windows app. If the base check passed but the requested project needs another SDK, report that requirement and offer to install its matching SDK rather than declaring the project ready. If the user declines, print the command for later use.

WinApp CLI (no admin needed)

WinApp CLI is a per-user MSIX package, so install or upgrade it without asking and tell the user what changed. If winapp is missing, install it. If it is below released 0.7.0, upgrade it. Skip both when the installed version already meets the minimum:

# When winapp is missing
winget install --id Microsoft.WinAppCli --exact --silent --accept-package-agreements --accept-source-agreements

# When winapp does not meet the released 0.7.0 minimum
winget upgrade --id Microsoft.WinAppCli --exact --silent --accept-package-agreements --accept-source-agreements

Refresh PATH after any winget install or upgrade:

$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine') + ';' +
            [Environment]::GetEnvironmentVariable('Path','User')

Run the version detection again. If a released 0.7.0 or later is still unavailable, report the actual version and mark setup blocked; do not fall back to older commands. A prerelease doesn't meet the requirement unless the user asks for preview validation.

Developer Mode (ask first)

Developer Mode requires admin elevation. Ask the user before triggering UAC. Only if they agree, elevate this one operation:

Start-Process powershell -Verb RunAs -ArgumentList @(
    '-NoProfile','-Command',
    "New-Item -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock' -Force | Out-Null; " +
    "Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock' " +
    "-Name AllowDevelopmentWithoutDevLicense -Type DWord -Value 1"
) -Wait

If the user declines or dismisses UAC, continue to the summary and print the command for later use.

Additional requirements for the requested workflow

Workflow Additional requirements
Native AOT publish/run Windows native compiler/linker toolchain: Visual Studio or Build Tools with Desktop development with C++, including the target architecture's tools and Windows SDK. See Native AOT prerequisites. These are not required for normal JIT iteration.
Windows Sandbox app runs and UI automation (preferred when available) WinApp's integration requires Windows 11 24H2+, hardware virtualization, and a working Windows Sandbox feature/client. Supported editions include Pro, Enterprise, and Education; not Home. Input/capture needs an unlocked host and a connected, non-minimized client. See WinApp Sandbox prerequisites.

Report these separately from the base toolchain. winapp target snapshot sandbox --json inspects an existing guest without starting or repairing it; "no target running" alone does not mean the Windows feature is unavailable. winui-ui-testing Step 1 defines what to do when Windows Sandbox is unavailable.

Enabling Windows Sandbox is a user action (admin plus a reboot): ask the user to open Turn Windows features on or off, select Windows Sandbox, and restart if prompted. Hardware virtualization must be enabled; a VM may also require nested virtualization. See Microsoft's supported editions and installation steps.

Final summary

Always print a single summary:

==== winui-setup summary ====
.NET SDK >= 8.0.100     [>] already present (10.0.100)
WinApp CLI >= 0.7.0     [OK] upgraded to 0.7.0
Developer Mode          [OK] enabled

Only report readiness for the workflows whose requirements passed. If the current harness exposes the winui-dev orchestrator agent, start a fresh session with that agent and ask it to build a WinUI app. Otherwise, start a fresh session in the current harness and ask it to perform the WinUI task; it will load the relevant winui-* skills on demand.

For GitHub Copilot CLI, for example:

copilot --agent winui:winui-dev -p "build me a WinUI 3 markdown editor"

Things to NOT do

  • Do not install Visual Studio; it is optional. Native AOT needs only the MSVC C++ build tools, a separate, explicitly approved setup.
  • Do not install or upgrade the user's AI coding harness; this skill manages Windows/WinUI development prerequisites only.
  • Do not elevate the entire session; request elevation only for the specific approved setup operation.
  • Do not silently retry failed installs.

04 同仓库更多 Skills

microsoft
microsoft/winappCli

WPF 至 WinUI 3 应用迁移

winui-wpf-migration

将 WPF 应用迁移或移植到 WinUI 3:命名空间(System.Windows 到 Microsoft.UI.Xaml)、控件映射(DataGrid、WrapPanel、TabControl)、Dispatcher 到 DispatcherQueue、图像处理、使用 CommunityToolkit.Mvvm 的 MVVM、ThemeResource。在转换 WPF 代码或修复迁移构建错误时使用。

软件开发工程师代码实现
★ 1.4k
microsoft
microsoft/winappCli

Windows 桌面应用 UI 自动化测试

winui-ui-testing

使用 winapp ui harness 为 Windows 桌面应用(WinUI 3、WPF、WinForms、Win32)编写并运行自动化 UI 测试:一个批处理脚本,支持断言、输入、文件选择器、对话框、截图,可在本地或 Windows Sandbox 中运行。当用户要求 UI 测试或端到端验证某个功能时使用。

测试工程师测试与质量保障
★ 1.4k
microsoft
microsoft/winappCli

WinUI 3 应用打包与发布

winui-packaging

使用 WinApp CLI 0.7+ 对 WinUI 3 应用进行 MSIX 打包、签名并发布到 Microsoft Store:包括项目打包、Native AOT、证书、自包含部署和 CI/CD。在发布 WinUI 应用时使用。不适用于仅引用 Windows App SDK 的 WPF、WinForms 或 Electron 应用。

软件开发工程师部署与发布管理
★ 1.4k
microsoft
microsoft/winappCli

WinUI 应用开发工作流

winui-dev-workflow

使用 WinApp CLI 0.7+ 创建、构建、运行 WinUI 3 应用(C# 或 C++)并修复构建错误:winapp new、winapp run、Native AOT、崩溃诊断。适用于新建 WinUI 应用,或构建失败、发生崩溃的 WinUI 项目。不适用于仅引用 Windows App SDK 的 WPF、WinForms 或 Electron 应用。

软件开发工程师开发环境与工具链管理
★ 1.4k
microsoft
microsoft/winappCli

WinUI XAML 界面设计

winui-design

在编写或更改 WinUI 3 XAML 之前阅读:控件、页面与导航的选择、布局、Fluent Design、主题、可访问性、x:Bind、真实示例,以及使用 winapp find-api 检查 API 是否存在。不适用于 WPF 或 WinForms UI,即使应用使用了 Windows App SDK。

软件开发工程师前端开发与界面实现
★ 1.4k
microsoft
microsoft/winappCli

WinUI 3 代码审查

winui-code-review

审查 WinUI 3 代码或变更的质量:MVVM、x:Bind 正确性、可访问性、主题、安全性、性能以及 WinUI 分析器发现的问题。当被要求审查或审计 WinUI 应用或其待提交的变更时使用,或在提交前使用。可发现编译器和 UI 测试遗漏的问题。

软件开发工程师测试与质量保障
★ 1.4k