Skip to content

Commit 9dff82b

Browse files
authored
Merge pull request #4159 from MicrosoftDocs/copilot-vs
How to use GitHub Copilot to create WinUI 3 / Windows App SDK apps in Visual Studio
2 parents e285a60 + 0a1695f commit 9dff82b

9 files changed

+95
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
title: How to use GitHub Copilot to create WinUI 3 / Windows App SDK apps in Visual Studio
3+
description: Get started with WinUI 3 / Windows App SDK by integrating GitHub Copilot code autocompletion capabilities into Visual Studio.
4+
ms.topic: article
5+
ms.date: 3/12/2024
6+
keywords: windows app sdk, winappsdk, winui3, copilot
7+
ms.author: mikben
8+
author: matchamatch
9+
ms.localizationpriority: medium
10+
ms.custom: template-quickstart
11+
audience: new-desktop-app-developers
12+
content-type: how-to
13+
---
14+
15+
# Use GitHub Copilot to create WinUI 3 / Windows App SDK apps in Visual Studio
16+
17+
In this how-to, we'll demonstrate how [GitHub Copilot](https://github.com/features/copilot) can be used to build WinUI 3 / Windows App SDK desktop apps in Visual Studio. This guide builds upon *[What is the GitHub Copilot extension for Visual Studio?](/visualstudio/ide/visual-studio-github-copilot-extension)*, offering tailored tips and best practices for Copilot-assisted WinUI 3 app development.
18+
19+
:::image type="content" source="images/github-copilot-winui-vs/github-copilot-extension-example.gif" alt-text="Animated screenshot that shows the code completion capabilities of the GitHub Copilot extension.":::
20+
21+
## Prerequisites
22+
23+
- [Visual Studio 2022 (v17.6+) and Tools for Windows App SDK](../windows-app-sdk/set-up-your-development-environment.md)
24+
- 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.
25+
- Familiarity with C# and WinUI 3 / Windows App SDK.
26+
27+
## Installation
28+
29+
1. In Visual Studio, select **Extensions** > **Manage Extensions**.
30+
2. Search for "GitHub Copilot" and click `Download`. Optionally, you can also install the [GitHub Copilot Chat Extension](https://marketplace.visualstudio.com/items?itemName=GitHub.copilot-chat) to enable Copilot's interface.
31+
3. Restart Visual Studio.
32+
4. Click `Modify` when prompted to install the extension.
33+
34+
35+
## Use GitHub Copilot
36+
37+
### Autocomplete your code snippets
38+
39+
The GitHub Copilot extension provides real-time code suggestions and completions based on the code you write. The most straightforward way to use Copilot is to start typing code in the editor, and Copilot will try to autocomplete your code snippet. You can then accept or dismiss the suggestions:
40+
41+
<!-- todo: animated gifs as an optimization -->
42+
43+
:::image type="content" source="images/github-copilot-winui-vs/1-basic-autocomplete.png" alt-text="Screenshot that shows the code completion capabilities of the GitHub Copilot extension (basic autocomplete).":::
44+
45+
### Generate multiple autocomplete suggestions
46+
47+
Select `Edit` -> `Copilot suggestions` -> `Open Copilot`. A window will open with a list of suggestions based on the latest cursor position:
48+
49+
:::image type="content" source="images/github-copilot-winui-vs/2-generate-multiple-autocomplete-suggestions.png" alt-text="Screenshot that shows the code completion capabilities of the GitHub Copilot extension (multiple autocomplete).":::
50+
51+
### Prompt Copilot with plain-language comments
52+
53+
Although Copilot is used primarily for code completion, you can also use natural language comments to guide Copilot in generating specific code snippets. For example, you can use comments to request a specific feature or functionality:
54+
55+
:::image type="content" source="images/github-copilot-winui-vs/3-prompt-copilot-with-inline-comment.png" alt-text="Screenshot that shows the code completion capabilities of the GitHub Copilot extension (prompting).":::
56+
57+
### Use temporary comments to add code from other files to Copilot's context
58+
59+
If you're working on a code-behind file and want Copilot to incorporate context from the associated XAML file, you can use temporary comments to include this additional code within Copilot's context. Here's an example of how you can specify the XAML code first, and then have Copilot generate the corresponding C# code:
60+
61+
:::image type="content" source="images/github-copilot-winui-vs/4-add-context-temporary-comments.png" alt-text="Screenshot that shows the code completion capabilities of the GitHub Copilot extension (context expansion).":::
62+
63+
### Ask Copilot to explain how something works with inline comments
64+
65+
You can use inline comments to ask Copilot to explain how a specific piece of code works. This is similar to using the Copilot Chat Extension, except your prompt is typed directly into the code editor:
66+
67+
:::image type="content" source="images/github-copilot-winui-vs/5-ask-copilot-inline-explanation.png" alt-text="Screenshot that shows the code completion capabilities of the GitHub Copilot extension (explain).":::
68+
69+
### Use Copilot to test code standards
70+
71+
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:
72+
73+
:::image type="content" source="images/github-copilot-winui-vs/6-enforce-code-standards.png" alt-text="Screenshot that shows the code completion capabilities of the GitHub Copilot extension (standards).":::
74+
75+
## Recap
76+
77+
In this how-to, we demonstrated how to use the GitHub Copilot extension to assist you with WinUI 3 / Windows App SDK desktop app development in Visual Studio. We covered how to:
78+
79+
- Autocomplete your code snippets.
80+
- Generate multiple autocomplete suggestions.
81+
- Prompt Copilot with plain-language comments.
82+
- Use temporary comments to add code from other files to Copilot's context.
83+
- Ask Copilot to explain how something works with inline comments.
84+
- Use Copilot to test and enforce code standards.
85+
86+
87+
## Related
88+
89+
- [Sample applications for Windows development](../get-started/samples.md)
90+
- [Windows developer FAQ](../get-started/windows-developer-faq.yml)
91+
- [Windows developer glossary](../get-started/windows-developer-glossary.md)
92+
- [Windows development best practices](../get-started/best-practices.md)
93+
- [How to target multiple platforms with your WinUI 3 app](uno-multiplatform.md)
9.74 KB
Loading
19.8 KB
Loading
6.51 KB
Loading
15.6 KB
Loading
14 KB
Loading
16.1 KB
Loading
316 KB
Loading

hub/apps/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ items:
363363
href: how-tos/chatgpt-openai-winui3.md
364364
- name: Add DALL-E image generation to your WinUI 3 desktop app
365365
href: how-tos/dall-e-winui3.md
366+
- name: Use Github Copilot to build WinUI 3 apps in Visual Studio
367+
href: how-tos/github-copilot-winui-vs.md
366368
- name: Target multiple platforms with WinUI 3
367369
href: how-tos/uno-multiplatform.md
368370
- name: About migrating from UWP to Windows App SDK

0 commit comments

Comments
 (0)