Skip to content

Dotnet Templates: use winappCli 3.0.1 (Microsoft.Windows.SDK.BuildTools.WinApp)#6455

Merged
DinahK-2SO merged 12 commits intouser/muyuanli/dotnetnewtemplatefrom
user/DinahK-2SO/use_winapp
May 8, 2026
Merged

Dotnet Templates: use winappCli 3.0.1 (Microsoft.Windows.SDK.BuildTools.WinApp)#6455
DinahK-2SO merged 12 commits intouser/muyuanli/dotnetnewtemplatefrom
user/DinahK-2SO/use_winapp

Conversation

@DinahK-2SO
Copy link
Copy Markdown
Contributor

@DinahK-2SO DinahK-2SO commented May 6, 2026

Summary

  1. Make dotnet run works out of box on the WinUI templates — wire the new
    Microsoft.Windows.SDK.BuildTools.WinApp 0.3.1
    NuGet package into the four packaged WinUI C# templates so users get
    loose-layout package identity + AUMID launch out of the box.
  2. Modernize the agent instructionsAgents.md and the
    instructions/*.instructions.md files now teach AI agents to use the
    public winapp CLI (winappCli 0.3) instead of hand-rolled
    Add-AppxPackage -Register / MakeAppx / SignTool invocations.
  3. Update README
  4. Extra fixes of errors in existing templates.

Quick start

dotnet new winui -n MyApp
cd MyApp

# dotnet build
dotnet run

Extra fixes

Below are extra fixes and their manual test steps:

  1. unit test
dotnet new winui utApp
cd utApp
dotnet run

after fix: successful launch, no error.

  1. winui-dialog
dotnet new winui -n DialogHost
cd DialogHost
dotnet new winui-dialog -n MyConfirmDialog --project DialogHost.csproj

(manually) add a button to demo the new dialog item

in MainPage.xaml:

    <Grid>
        <Button x:Name="ShowDialogButton"
                Content="Show dialog"
                Click="ShowDialogButton_Click"
                HorizontalAlignment="Center"
                VerticalAlignment="Center" />
    </Grid>

in MainPage.xaml.cs:

using Microsoft.UI.Xaml;

    private async void ShowDialogButton_Click(object sender, RoutedEventArgs e)
    {
        var dialog = new MyConfirmDialog
        {
            XamlRoot = this.XamlRoot,
        };
        await dialog.ShowAsync();
    }

run

dotnet run

after fix: successful launch, no error.
clicking the button shows the new dialog item.

  1. winui-templatedcontrol
dotnet new winui -n TCdemo
cd TCdemo
dotnet new winui-templatedcontrol -n MyBadge --project TCdemo.csproj

after fix: item created with Generic.xaml:

|- MyBadge.cs
|- Themes/
        |- Generic.xaml

Note: When running dotnet new winui-templatedcontrol -n <item name> --project <project name>.csproj, if the Themes/Generic.xaml file already exists, the creation will be blocked with an error as below:

dotnet new winui-templatedcontrol -n MyBadge2 --project test1.csproj

- Creating this template will make changes to existing files:
-  Overwrite   ./Themes/Generic.xaml

- To create the template anyway, run the command with '--force' option:

This issue can be resolved via flag -I false or --IncludeDefaultStyle false, who skips creating the Generic.xaml file. Here is an example command:

dotnet new winui-templatedcontrol -n MyBadge2 --project TCdemo.csproj -I false

The error message is generated by the dotnet template engine, it cannot be modified from the template side.
So we're adding hint to use -I false in comments of the generated code.

  1. winui-resw
    After fix: the "Resources" string in output *.resw file won't be replaced by brutal force.

  2. winui-tabview
    Fix the caption button overlap.

After fix 5:
image

Before fix 5:
image

…SDK.BuildTools.WinApp for `dotnet run`

Reference the new `Microsoft.Windows.SDK.BuildTools.WinApp` NuGet package
(0.3.1) from the four packaged WinUI C# templates so that `dotnet run`
"just works" -- the package hooks the .NET CLI Run target to register a
loose-layout debug identity via the winapp CLI and launch the app via
AUMID. The same source feeds both the `dotnet new` template pack and
the VS extension VSIX, so VS-instantiated projects also pick up the
new package automatically (via the existing
`WindowsAppSDK.TemplateUtilities.NuGetPackageInstaller` wizard).

Project files (apply to both `dotnet new` and VSIX):
  * SingleProjectPackagedApp/ProjectTemplate.csproj
  * NavigationApp/ProjectTemplate.csproj
  * MvvmApp/ProjectTemplate.csproj
  * TabViewApp/ProjectTemplate.csproj
    -- add `<PackageReference Include="Microsoft.Windows.SDK.BuildTools.WinApp"
       Version="$WindowsSdkBuildToolsWinAppVersion$" />` inside the existing
       `UseLatestWindowsAppSDK` conditional block.

`dotnet new` templating (parameter + post-action):
  * Dotnet/templates/single-project/.template.config/template.json
  * Dotnet/templates/navigation-app/.template.config/template.json
  * Dotnet/templates/mvvm-app/.template.config/template.json
  * Dotnet/templates/tabview-app/.template.config/template.json
    -- add `windowsSdkBuildToolsWinAppVersion` parameter (default `0.3.1`).
    -- add post-action to update the package to latest stable.

VSIX templating (`$NuGetPackages$` list consumed by the VS wizard):
  * SingleProjectPackagedApp/WinUI.Desktop.Cs.*.vstemplate
  * NavigationApp/WinUI.Desktop.Cs.*.vstemplate
  * MvvmApp/WinUI.Desktop.Cs.*.vstemplate
  * TabViewApp/WinUI.Desktop.Cs.*.vstemplate
    -- append `Microsoft.Windows.SDK.BuildTools.WinApp` so the VSIX
       wizard installs latest stable when the project is created.

Skipped: ClassLibrary (no app), UnitTestApp (test container), and
PackagedApp (multi-project WAP layout where `dotnet run` on the C# child
isn't packaged anyway).

Agent instructions (`dev/Templates/Dotnet/templates/single-project/`)
modernized to reflect the winappCli 0.3 surface:
  * Agents.md
    -- "Build, Run & Deploy" rewritten: promote `dotnet run` (auto-invokes
       `winapp run` via the new NuGet) as the inner-loop default; demote
       manual `Add-AppxPackage -Register` to a documented fallback.
    -- Fix incorrect `winapp run` invocation (it takes the build output
       *folder*, not the .exe).
    -- Fix `$env:PROCESSOR_ARCHITECTURE` mapping (returns `AMD64` on x64
       boxes; MSBuild needs `x64`).
    -- Add a winapp CLI command cheatsheet (run, create-debug-identity,
       unregister, cert generate/info, sign, pack, manifest update-assets,
       manifest add-alias, tool).
    -- Document MSBuild knobs: `EnableWinAppRunSupport`,
       `WinAppRunUseExecutionAlias`, `WinAppRunNoLaunch`,
       `WinAppLaunchArgs`.
    -- Replace stale Windows AI prerequisites (LAF token,
       `<WindowsAppSDKSelfContained>` overrides) with the current
       package-identity / capability / hardware-gating model.
  * instructions/winui-best-practices.instructions.md
    -- Common-pitfalls table now recommends `winapp unregister` +
       `dotnet run` (and `winapp run --clean` for first-run resets)
       instead of `Add-AppxPackage -Register`.
  * instructions/security.instructions.md
    -- Replace bare "enable code signing" bullet with concrete
       `winapp cert generate` / `cert info` / `sign` / `pack --cert`
       workflow.
  * instructions/testing.instructions.md
    -- Drop hardcoded `-p:Platform=x64`; use the same `$Platform`
       detection convention as Agents.md so tests work on ARM64
       dev boxes.
@DinahK-2SO DinahK-2SO requested a review from lei9444 May 6, 2026 08:43
@DinahK-2SO DinahK-2SO changed the title Templates: use winapp CLI for run/debug; reference Microsoft.Windows.SDK.BuildTools.WinApp for dotnet run Dotnet Templates: use winapp CLI for run/debug; reference Microsoft.Windows.SDK.BuildTools.WinApp for dotnet run May 6, 2026
@DinahK-2SO DinahK-2SO changed the title Dotnet Templates: use winapp CLI for run/debug; reference Microsoft.Windows.SDK.BuildTools.WinApp for dotnet run Dotnet Templates: use winappCli 3.0.1 (Microsoft.Windows.SDK.BuildTools.WinApp) May 6, 2026
@DinahK-2SO DinahK-2SO requested a review from niels9001 May 6, 2026 16:01
@DinahK-2SO
Copy link
Copy Markdown
Contributor Author

also adding @nmetulev for review

…t/WindowsAppSDK into user/DinahK-2SO/use_winapp
@nmetulev
Copy link
Copy Markdown
Member

nmetulev commented May 7, 2026

Template validation findings (TODO)

⚠️ Note: This validation pass was performed with the help of GitHub Copilot CLI by generating each template, building, and (where applicable) running the resulting app. Please verify each finding before acting on it — Copilot can be wrong about root causes.

I generated and ran every template (winui, winui-mvvm, winui-navview, winui-tabview, winui-lib, winui-unittest, winui-page, winui-window, winui-dialog, winui-usercontrol, winui-templatedcontrol, winui-resourcedictionary, winui-resw). 9 of 13 work cleanly. 4 issues to look at:

🔴 Blockers

1. winui-unittest — won't build out of the box
The generated .csproj has no <PackageReference> entries at all — missing Microsoft.WindowsAppSDK, Microsoft.Windows.SDK.BuildTools, MSTest.TestFramework, MSTest.TestAdapter, Microsoft.NET.Test.Sdk, and Microsoft.VisualStudio.TestPlatform.TestFramework. Result: 19+ CS0234/CS0246 errors on a fresh dotnet new winui-unittest.

2. winui-dialog — crashes the app at runtime
<ItemName>.xaml is generated with Style="{StaticResource Default<ItemName>Style}", but no such style is defined anywhere. Calling ShowAsync() throws a XAML parse exception and the app crashes. Confirmed by wiring the generated dialog into a fresh winui project and running.
Fix: drop the Style= line from the template, or also generate/ship a default style.

🟡 Quality bugs

3. winui-templatedcontrol — control renders as nothing
Generates <ItemName>.cs setting DefaultStyleKey = typeof(<ItemName>), but does not scaffold a Themes/Generic.xaml with a default Style + ControlTemplate. Builds fine, but the control has no template → no visual at runtime. Surprising for a "templated control" template.

4. winui-resw — wrong type names in resheaders
The <resheader name="reader"> / writer values say System.<ItemName>.ResXResourceReader, System.Windows.Forms, .... Looks like the template parameter token replaced the literal text Resources inside the namespace System.Resources.ResXResourceReader with the user-supplied item name. Should always be System.Resources.ResX{Reader,Writer} regardless of item name. (Doesn't break resgen in practice, but the file is technically broken.)

@nmetulev
Copy link
Copy Markdown
Member

nmetulev commented May 7, 2026

In addition the tabed template titlebar is shorter than the buttons and they overflow on hover
image

@niels9001
Copy link
Copy Markdown
Contributor

In addition the tabed template titlebar is shorter than the buttons and they overflow on hover
image

See #6407 for comments.

We need DefaultContentDialogStyleto ensure the dialog pick ups the modern style from WinUI vs falling back to an OS style that looks dated. The style should be hardcoded thouhgh and NOT be overwritten by generating the template.

There's a potential fix for the captionbuttons overlapping in the TabView template too.

@DinahK-2SO DinahK-2SO merged commit b885268 into user/muyuanli/dotnetnewtemplate May 8, 2026
1 check passed
@DinahK-2SO DinahK-2SO deleted the user/DinahK-2SO/use_winapp branch May 8, 2026 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants