You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: hub/apps/how-tos/github-copilot-winui-vs.md
+22-6Lines changed: 22 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ In this how-to, we'll demonstrate how [GitHub Copilot](https://github.com/featur
18
18
## Prerequisites
19
19
20
20
- 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.
22
22
- Familiarity with C#, WinUI, and Windows App SDK.
23
23
24
24
## Use GitHub Copilot
@@ -93,11 +93,27 @@ You can also ask for explanations directly in the Chat panel using the `/explain
93
93
> [!TIP]
94
94
> 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.
95
95
96
-
### Use Copilot to test code standards
96
+
### Use Copilot to enforce code standards
97
97
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:
99
99
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.
101
117
102
118
## WinUI 3 patterns to watch for
103
119
@@ -121,11 +137,11 @@ In this how-to, we demonstrated how to use GitHub Copilot in Visual Studio to as
121
137
122
138
- Autocomplete your code snippets.
123
139
- 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**.
125
141
- Prompt Copilot with plain-language comments.
126
142
- Use `#file` references or temporary comments to add context from other files.
127
143
- 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.
129
145
- Identify and correct UWP patterns that Copilot may suggest in WinUI 3 projects.
0 commit comments