Skip to content

Commit 76b9351

Browse files
Full accuracy pass on Copilot WinUI how-to
- Prerequisites: Copilot free tier now available; update subscription note - 'Test code standards': replace stale inline-comment approach with .github/copilot-instructions.md pattern + Chat review question - Delete orphaned screenshot 6-enforce-code-standards.png - Recap: 'Ask Copilot' -> right-click Chat; standards -> copilot-instructions.md Co-authored-by: Copilot <[email protected]>
1 parent ac61344 commit 76b9351

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

hub/apps/how-tos/github-copilot-winui-vs.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ In this how-to, we'll demonstrate how [GitHub Copilot](https://github.com/featur
1818
## Prerequisites
1919

2020
- Visual Studio 2022 (v17.10 or later) or Visual Studio 2026, with the **WinUI application development** workload applied (see [Set up your environment and create your first WinUI project](../get-started/start-here.md) for setup details). GitHub Copilot is included in Visual Studio 2022 v17.10 and later by default.
21-
- An active subscription to [GitHub Copilot](https://github.com/features/copilot/plans) associated with the GitHub account that you sign in to Visual Studio with.
21+
- A GitHub account with access to [GitHub Copilot](https://github.com/features/copilot/plans). GitHub Copilot is available for free for individual developers; paid plans are also available. Sign in to Visual Studio with the same GitHub account.
2222
- Familiarity with C#, WinUI, and Windows App SDK.
2323

2424
## Use GitHub Copilot
@@ -93,11 +93,27 @@ You can also ask for explanations directly in the Chat panel using the `/explain
9393
> [!TIP]
9494
> Slash commands like `/explain`, `/fix`, and `/doc` are shortcuts in the Chat panel that tell Copilot exactly what kind of help you want. Type `/` in the Chat input to see all available commands.
9595
96-
### Use Copilot to test code standards
96+
### Use Copilot to enforce code standards
9797

98-
You can use Copilot to generate code that adheres to your project's coding standards, and to test any given snippet's adherence to those standards. Here's an example of how you can use inline comments to specify two conventions, and then have Copilot validate the code snippet against these conventions:
98+
The most reliable way to have Copilot follow your project's coding conventions is to add a `.github/copilot-instructions.md` file to your repository. Copilot reads this file automatically and applies the instructions to all suggestions in that repo. For example:
9999

100-
:::image type="content" source="images/github-copilot-winui-vs/6-enforce-code-standards.png" alt-text="Screenshot that shows the code completion capabilities of GitHub Copilot (standards).":::
100+
```markdown
101+
# Copilot instructions
102+
103+
- Use DispatcherQueue.TryEnqueue for all UI thread dispatch, never CoreDispatcher
104+
- Always set XamlRoot when showing a ContentDialog
105+
- Use the MVVM pattern with CommunityToolkit.Mvvm ObservableObject and RelayCommand
106+
- Target net10.0-windows10.0.19041.0 — do not use plain net10.0
107+
```
108+
109+
You can also ask Copilot to review a code snippet against specific standards in the Chat panel:
110+
111+
```
112+
Does this code follow the MVVM pattern correctly for a WinUI 3 app?
113+
```
114+
115+
> [!TIP]
116+
> For team-wide consistency, commit `.github/copilot-instructions.md` to source control. Every developer on the team will get the same Copilot behavior without any per-machine configuration.
101117
102118
## WinUI 3 patterns to watch for
103119

@@ -121,11 +137,11 @@ In this how-to, we demonstrated how to use GitHub Copilot in Visual Studio to as
121137

122138
- Autocomplete your code snippets.
123139
- Use the Copilot Chat panel for multi-step WinUI questions and file references.
124-
- Generate autocomplete suggestions inline with Ask Copilot.
140+
- Generate inline suggestions using right-click > **Chat**.
125141
- Prompt Copilot with plain-language comments.
126142
- Use `#file` references or temporary comments to add context from other files.
127143
- Ask Copilot to explain code using **Copilot Actions** > **Explain** or the `/explain` slash command in Chat.
128-
- Use Copilot to test and enforce code standards.
144+
- Use Copilot to enforce code standards with `.github/copilot-instructions.md` or Chat review.
129145
- Identify and correct UWP patterns that Copilot may suggest in WinUI 3 projects.
130146

131147
## Related content
Binary file not shown.

0 commit comments

Comments
 (0)