WinUI templates for dotnet new and VSIX#6407
Conversation
75d7c86 to
e3fc78f
Compare
…ty, and testing guidelines (#6217)
* Add pipelines * Update readme
* Adding TitleBar and .ico * Adding the ContentDialog ItemTemplate * Adding NavigationView template * Missed a csharp template and added * Push * Update WinAppSdk.CSharp.DotnetNewTemplates.csproj * Clean up navview project * Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/HomePage.xaml.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/AboutPage.xaml.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/Pages/SettingsPage.xaml.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/App.xaml.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dev/VSIX/ItemTemplates/Neutral/CSharp/ContentDialog/ContentDialog.xaml.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update dev/VSIX/ProjectTemplates/Desktop/CSharp/NavigationApp/MainWindow.xaml.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Add default case with exception to navigation switch statement (#6252) * Initial plan * Add default case throwing InvalidOperationException in navigation switch statement Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: niels9001 <9866362+niels9001@users.noreply.github.com>
* Add missing item-content-dialog template for dotnet new The csproj referenced templates/item-content-dialog/ but the directory did not exist, which would cause dotnet pack to produce an incomplete package. Create the template.json, dotnetcli.host.json, and the XAML and code-behind files for a WinUI 3 ContentDialog item template. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add packaged template to NuGet template pack The templates/packaged/ directory existed with a full template.json and solution file but was never included in the csproj ItemGroups, so it would not ship in the NuGet package. Add the ItemGroup that packs the template config, solution, BlankApp, and WapProj sources. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update README with packaged and content-dialog templates The template table was missing the wasdk-packaged and wasdk-item-dialog entries. Add both so the README accurately documents all templates shipped in the pack. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add language and type tags to all template.json files Without the 'tags' property, 'dotnet new list' does not show the language column and template discoverability is reduced. Add tags.language=C# and tags.type (project, solution, or item) to every template. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add postActions for automatic NuGet restore After 'dotnet new' creates a project, the user currently has to manually run 'dotnet restore'. Add the standard NuGet restore post- action (actionId 210D431B) to the four project templates so packages are restored automatically. Item templates do not need this. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add Windows-only OS constraint to all templates WinUI 3 / Windows App SDK templates only work on Windows. Without the constraint, 'dotnet new list' shows them on Linux and macOS where they cannot build, leading to confusing errors. Add the os constraint so the templates are hidden on non-Windows hosts. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add description fields to template parameters The single-project, class-library, and unit-test templates were missing description fields on their user-facing parameters. The packaged template already had them. Add matching descriptions so 'dotnet new <template> --help' displays useful parameter documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add description fields to dotnetcli.host.json files The packaged template's host file already had descriptions but the single-project, class-library, unit-test, and item-blank-window host files did not. Add descriptions so 'dotnet new <template> --help' displays useful help text for every parameter. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add Copyright, license acceptance, and release notes to csproj The NuGet package was missing Copyright, PackageRequireLicenseAcceptance, and PackageReleaseNotes metadata. Add them for completeness and better presentation on NuGet feeds. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update default dotnetVersion from net8.0 to net9.0 .NET 9.0 is the current release. Update the default TFM across all four project templates and their dotnetcli.host.json description examples. Users can still override with --dotnet-version net8.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Use https:// for JSON schema URLs All template.json and dotnetcli.host.json files used http:// for the schema store URLs. Update to https:// for consistency and security. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Revert packaged template from dotnet new pack The wasdk-packaged template uses a WAP project (.wapproj) which the dotnet CLI does not understand, so it cannot be used with 'dotnet new'. Remove the packaged template ItemGroup from the csproj, remove it from the README, and restore its template.json and dotnetcli.host.json to their pre-modification state. This reverts the packaged-related portions of commits 31f65f2, b8c76b7, 80c1b8f, 63d5abf, ff0bc38, 7c03a19, and 4891155. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Use existing VS ContentDialog sources instead of hand-crafted copies The ContentDialog XAML and code-behind already exist at ItemTemplates/Neutral/CSharp/ContentDialog/. Link those files in the csproj instead of maintaining separate copies, matching the pattern used by the BlankWindow item template. This keeps a single source of truth and preserves the original button click handlers. Also update template.json sourceName and primaryOutputs to match the original filenames (ContentDialog, not ContentDialogItem), and remove the now-unnecessary Compile Remove directive. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Align packaged template config with other templates The previous revert restored the packaged template.json and dotnetcli.host.json to their original state, making them inconsistent with the rest of the templates. Re-apply the same improvements: add tags, constraints, postActions, update schema to https://, and default TFM to net9.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Remove templates/packaged/ directory The packaged template uses a WAP project (.wapproj) which the dotnet CLI does not support, so it is not included in the NuGet template pack. Remove the unused directory to avoid confusion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Update default dotnetVersion from net9.0 to net10.0 .NET 10.0 is the latest officially supported version. Update the default TFM and help text examples across all project templates. Users can still override with --dotnet-version net8.0 or net9.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Rename template shortNames from wasdk-* to winui3-* Use winui3- prefix instead of wasdk- since WinUI 3 is the product name users recognize, not the shipping vehicle (Windows App SDK). wasdk-single -> winui3 wasdk-classlib -> winui3-lib wasdk-unittest -> winui3-unittest wasdk-item-blankwin -> winui3-window wasdk-item-dialog -> winui3-dialog Also update display names and default project names to match. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add winui3-page and winui3-usercontrol item templates Add two new item templates that link existing VS template sources from ItemTemplates/Neutral/CSharp/: winui3-page - BlankPage (Page with XAML and code-behind) winui3-usercontrol - UserControl (UserControl with XAML and code-behind) Both follow the same pattern as winui3-window and winui3-dialog: the template.config is maintained locally while XAML/code-behind are linked from the shared VS template sources. Note: the dotnet new template engine does not support verifying that an existing project exists before adding an item template. The msbuild:RootNamespace binding will fall back to the default value if no project is found. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add project-capability and sdk-version constraints to item templates Item templates (window, page, usercontrol, dialog) should only appear in 'dotnet new list' when run inside a C# project folder. Add a 'project-capability' constraint with 'CSharp' so the templates are hidden when no C# project is found in the current directory. Also add an sdk-version constraint requiring .NET 8.0 or later. Inspired by https://github.com/egvijayanand/winui-templates which uses the same approach. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Add sdk-version constraint to project templates Require .NET 8.0 SDK or later for the three project templates (single-project, class-library, unit-test). The templates target net10.0-windows and will not work on older SDKs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * chore(project): update NoWarn property to include CS2008 warning * feat(templates): update template identities to use WinUI naming convention * feat(templates): add symbols section to various template configurations * feat(templates): update dotnetVersion to support .NET 8, 9, and 10 choices * template renamings * User/muyuanli/naming improvements (#6256) * template renamings * Update naming and schema * Add back agents and instructions --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Muyuan Li (from Dev Box) <muyuanli@microsoft.com> Co-authored-by: Muyuan Li <116717757+MuyuanMS@users.noreply.github.com>
* Enhance copilot instructions and project spec * Fix indentation
* complete nuspec * Update dev/VSIX/DotnetNewTemplates/WinAppSdk.CSharp.DotnetNewTemplates.csproj Co-authored-by: Niels Laute <niels.laute@live.nl> * Update dev/VSIX/DotnetNewTemplates/WinAppSdk.CSharp.DotnetNewTemplates.csproj Co-authored-by: Niels Laute <niels.laute@live.nl> * Update dev/VSIX/DotnetNewTemplates/README.md Co-authored-by: Niels Laute <niels.laute@live.nl> * Resolve comments --------- Co-authored-by: Niels Laute <niels.laute@live.nl>
* Update default dotnet version to be 10.0 * Update vstemplate to be dotnet 10 as well
* set dotnet version based on installed sdk version, and increase windows sdk in tfm * Add test script and fix existing issues with item templates --------- Co-authored-by: Nikola Metulev <nmetulev@users.noreply.github.com>
* added frame and mainpage to main window * winui template updates * adding mvvm template --------- Co-authored-by: Nikola Metulev <711864+nmetulev@users.noreply.github.com>
* Remove invalid classifications and add missing XAML The classications now match the classifications from the VSIX templates * Ensures IDE shows the correct field information Also makes min version a dropdown, and sets default based on current support lifecycles / recommendations. * Add missing min versions
4258460 to
f619e83
Compare
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
|
||
| Import the VSIX Directory.Build.props for CPM and shared settings. | ||
| --> | ||
| <Import Project="$(MSBuildThisFileDirectory)..\VSIX\Directory.Build.props" /> |
There was a problem hiding this comment.
it would be better to factor shared props into a Templates\Directory.Build.props that both Dotnet and VSIX chain into
| @@ -0,0 +1,30 @@ | |||
| Microsoft Visual Studio Solution File, Format Version 12.00 | |||
There was a problem hiding this comment.
Should this be in slnx format now instead?
There was a problem hiding this comment.
Can't this project use project references to pick up template details (None elements), like the VSIX project does? This approach seems brittle, with the dotnet project needing to know details of each template.
There was a problem hiding this comment.
Should we add the new item/project templates to the component/standalone VSIXes? Ideally, we'd keep these in sync.
cc: @lauren-ciha
There was a problem hiding this comment.
This is how we do it: We create the nuget-version of the templates, and then we just include that nuget in the VSIX installer rather than maintaining two sets of .NET templates.
There was a problem hiding this comment.
There was a problem hiding this comment.
might want to chain into this from \BuildAll.ps1
…rrored label of mvvmApp in VSIX
| // drag region so the tab strip acts as the title bar area. | ||
| ExtendsContentIntoTitleBar = true; | ||
| SetTitleBar(CustomDragRegion); | ||
| AppWindow.TitleBar.PreferredHeightOption = TitleBarHeightOption.Tall; |
There was a problem hiding this comment.
Remove this is to fix the caption buttons overlap issue that Nikola pointed out in the other PR (OR keep it but then we newd to increase the heights of the space where the tabs are rendered).
| xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
| xmlns:local="using:$rootnamespace$" | ||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
| Style="{StaticResource DefaultContentDialogStyle}" |
There was a problem hiding this comment.
This style is part of WinUI. Id we don't set it, the dialog will fallback to an OS style (== UWP/Windows 10/pre-Fluent Design) that looks very outdated.
…ls.WinApp) (#6455) ## Summary 1. **Make `dotnet run` works out of box on the WinUI templates** — wire the new [`Microsoft.Windows.SDK.BuildTools.WinApp 0.3.1`](https://www.nuget.org/packages/Microsoft.Windows.SDK.BuildTools.WinApp) 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 instructions** — `Agents.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 ```powershell 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. 2. 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: ```xml <Grid> <Button x:Name="ShowDialogButton" Content="Show dialog" Click="ShowDialogButton_Click" HorizontalAlignment="Center" VerticalAlignment="Center" /> </Grid> ``` in MainPage.xaml.cs: ```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 ```powershell dotnet run ``` after fix: successful launch, no error. clicking the button shows the new dialog item. 3. 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` ```diff - 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. 4. winui-resw After fix: the "Resources" string in output *.resw file won't be replaced by brutal force. 5. winui-tabview Fix the caption button overlap. After fix 5: <img width="1858" height="1171" alt="image" src="https://github.com/user-attachments/assets/5f154788-b565-4e1f-9d2c-b528e167bd89" /> Before fix 5: <img width="1895" height="378" alt="image" src="https://github.com/user-attachments/assets/b4667086-e261-447f-ba37-9e854477d63f" /> --------------------------------------------------- * dotnet templates 0.0.5-alpha * update readme * simplify readme * auto platform select * simplify * fix unittest, dialog, resw templates * Generic.xaml for templatedcontrol * Drop title-bar override in winui-tabview; restore DefaultContentDialogStyle in winui-dialog via a sourceName-safe placeholder. * update ut-app type * Restore TabView title-bar extension with DPI-aware caption-button inset to fix overlap.
…uyuanli/dotnetnewtemplate

This PR adds/updates the WinUI App templates:
dotnet new