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/copilot-chat-winui3.md
+24-34Lines changed: 24 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,27 @@
1
1
---
2
-
title: How to streamline your WinUI 3 / Windows App SDK development workflow with GitHub Copilot Chat
3
-
description: Get started with GitHub Copilot Chat by learning how to streamline your WinUI 3 / Windows App SDK development workflow with context-aware prompts
4
-
ms.topic: article
5
-
ms.date: 5/8/2024
6
-
keywords: windows app sdk, winappsdk, winui3, openai, chatgpt, copilot
2
+
title: How to streamline your WinUI 3 development workflow with GitHub Copilot Chat
3
+
description: Get started with GitHub Copilot Chat by learning how to streamline your WinUI 3 / Windows App SDK development workflow with context-aware prompts.
#Customer intent: As a Windows developer, I want to learn how to streamline my WinUI 3 / Windows App SDK development workflow with GitHub Copilot Chat in Visual Studio, so that I can build apps more efficiently.
11
10
---
12
11
13
12
# Streamline your WinUI 3 / Windows App SDK development workflow with GitHub Copilot Chat
14
13
15
14
This how-to is targeted at desktop application developers who want to streamline their WinUI 3 / Windows App SDK application development workflow with Github Copilot Chat in Visual Studio.
16
15
17
-
We'll start by using GitHub Copilot Chat to build a "Hello world" app with a single prompt, and then we'll demonstrate how GitHub Copilot Chat can be used to add a chat interface that displays responses from a mocked serverside component.
16
+
We'll start by using GitHub Copilot Chat to build a "Hello world" app with a single prompt, and then we'll demonstrate how GitHub Copilot Chat can be used to add a chat interface that displays responses from a mocked server-side component.
18
17
19
18
## Prerequisites
20
19
21
20
- Visual Studio 2022 [version 17.8](/visualstudio/releases/2022/release-history) or later
22
21
- An active [subscription](https://docs.github.com/en/billing/managing-billing-for-github-copilot/about-billing-for-github-copilot) to [GitHub Copilot for Individuals](https://docs.github.com/copilot/overview-of-github-copilot/about-github-copilot-for-individuals) or [GitHub Copilot for Business](https://docs.github.com/copilot/overview-of-github-copilot/about-github-copilot-for-business) associated with the GitHub account that you sign in to Visual Studio with.
23
22
-[**GitHub Copilot Chat**](/visualstudio/ide/visual-studio-github-copilot-chat) in Visual Studio.
24
-
- If you're using [Visual Studio version 17.10 Preview 3](/visualstudio/releases/2022/release-notes-preview) or later, GitHub Copilot Chat is included in the built-in, unified GitHub Copilot extension available as a recommended component in the Visual Studio Installer. It is installed by default with all workloads, unless you choose to exclude it during installation.
25
-
- Familiarity with C# and WinUI 3 / Windows App SDK.
26
-
23
+
- If you're using Visual Studio version 17.10 or later, GitHub Copilot Chat is included in the built-in, unified GitHub Copilot extension available as a recommended component in the Visual Studio Installer. It is installed by default with all workloads, unless you choose to exclude it during installation.
24
+
- Familiarity with C#, WinUI 3, and Windows App SDK.
27
25
28
26
## Prompting techniques
29
27
@@ -33,9 +31,9 @@ The goal of this how-to is to equip you with **vocabulary** and **prompting tech
33
31
34
32
In Visual Studio, select **View > GitHub Copilot Chat**.
35
33
36
-
:::image type="content" source="images/copilot-chat/0-view-github-copilot-chat.png" alt-text="Screenshot of Copilot Chat being selected":::
34
+
:::image type="content" source="images/copilot-chat/0-view-github-copilot-chat.png" alt-text="A screenshot of GitHub Copilot Chat being selected from Visual Studio's View menu.":::
37
35
38
-
This opens the **GitHub Copilot Chat pane** on the left side of the Visual Studio window. You can use this chat window to ask Copilot for help with your code. This technique is useful when you're working across multiple files and don't mind explicitly specifying the files that need to change, and it's the technique we'll focus on in this how-to.
36
+
This opens the **GitHub Copilot Chat pane** on right side of the Visual Studio window, depending on your configuration. You can use this chat window to ask Copilot for help with your code. This technique is useful when you're working across multiple files and don't mind explicitly specifying the files that need to change, and it's the technique we'll focus on in this how-to.
39
37
40
38
### Prompting through inline Copilot Chat
41
39
@@ -45,7 +43,6 @@ From any file's editor window, right click and select Ask Copilot to bring up th
45
43
46
44
This will reveal an inline chat window where you can prompt Copilot to assist you with the file you're currently working on. Use this when you're working within the context of a single file.
47
45
48
-
49
46
## Create a new WinUI 3 project
50
47
51
48
Type the following into the Copilot Chat window:
@@ -60,7 +57,6 @@ You should see instructions appear:
60
57
61
58
This highlights a limitation that you should be aware of: at the time of this writing, the Chat extension can't create a new project or file structure for you, but it *can* provide you with step-by-step instructions. Follow the instructions to create a new project.
62
59
63
-
64
60
## Display a "Hello, world!" message
65
61
66
62
Once your new project is created, type the following into the Copilot Chat window:
@@ -85,7 +81,7 @@ Update #MainWindow.xaml and #MainWindow.xaml.cs to display "Hello, world!" when
85
81
86
82
You should see Copilot generate the necessary code within code blocks labeled `MainWindow.xaml` and `MainWindow.xaml.cs`. These code blocks should each display two options: `Insert in new file` and `Preview`. Click `Preview`**while your cursor is active in the target file** to stage and accept the changes:
87
83
88
-
:::image type="content" source="images/copilot-chat/4-preview-codebehind.png" alt-text="Screenshot of the Preview button when working with the codebehind file":::
84
+
:::image type="content" source="images/copilot-chat/4-preview-codebehind.png" alt-text="Screenshot of the Preview button when working with the code-behind file":::
89
85
90
86
:::image type="content" source="images/copilot-chat/5-preview-markup.png" alt-text="Screenshot of the Preview button when working with the markup file":::
91
87
@@ -104,14 +100,13 @@ What files should I change in my #Solution in order to achieve <desired outcome>
104
100
Type the following into the Chat window:
105
101
106
102
```
107
-
Update #MainWindow.xaml and #MainWindow.xaml.cs to display ONLY "Hello, world!" when the app starts, removing extraneous buttons and their codebehind functionality as-needed. Directly modify the existing files. Do not explain yourself. Do not generate new files.
103
+
Update #MainWindow.xaml and #MainWindow.xaml.cs to display ONLY "Hello, world!" when the app starts, removing extraneous buttons and their code-behind functionality as-needed. Directly modify the existing files. Do not explain yourself. Do not generate new files.
108
104
```
109
105
110
-
Accept the suggested changes. You should see the button removed from the UI and the corresponding code removed from the codebehind file. Run the application to verify that only the "Hello, world!" message is displayed:
106
+
Accept the suggested changes. You should see the button removed from the UI and the corresponding code removed from the code-behind file. Run the application to verify that only the "Hello, world!" message is displayed:
111
107
112
108
:::image type="content" source="images/copilot-chat/6-results-hello-world.png" alt-text="Screenshot of the hello world results":::
113
109
114
-
115
110
## Build the chat interface
116
111
117
112
Next, we'll build a simple chat interface that lets you enter text and generate mocked responses. Type the following into the Chat window:
@@ -126,7 +121,7 @@ Update #MainWindow.xaml and #MainWindow.xaml.cs to build a chat interface with t
126
121
5. When I click the Send button, display the input text in a TextBlock, and update the ProgressBar to indicate that the app is waiting for a response. Mock the code that generates a response with a delay of 2 seconds, and then display a response that echoes the input text above the input.
127
122
6. Ensure that **TextBlock** text wraps to the next line when it reaches the edge of the window.
128
123
129
-
Remove extraneous code as-needed. Directly modify the existing files. Do not explain yourself. Do not generate new files. Ensure that every single numbered requirement is accounted for in the end result. Ensure that both the markup and codebehind files are updated to produce a fully functional chat interface that builds and meets the above-stated requirements. Take your time. Reveal only two code blocks representing the end result, one for each file.
124
+
Remove extraneous code as-needed. Directly modify the existing files. Do not explain yourself. Do not generate new files. Ensure that every single numbered requirement is accounted for in the end result. Ensure that both the markup and code-behind files are updated to produce a fully functional chat interface that builds and meets the above-stated requirements. Take your time. Reveal only two code blocks representing the end result, one for each file.
130
125
```
131
126
132
127
This is an example of **one-shot prompting**, where you're providing all requirements in a single prompt. This can be useful when you have a clear idea of what you want to build and you want to see Copilot generate the code to meet those requirements, but it also increases the likelihood that Copilot will generate code that doesn't quite satisfy your requirements.
@@ -135,7 +130,7 @@ This highlights an important consideration: If you provide Copilot with **precis
135
130
136
131
At the time of this writing, the above input generated the below output:
@@ -228,7 +223,6 @@ Which yielded the following UI:
228
223
229
224
:::image type="content" source="images/copilot-chat/7-working-example.png" alt-text="Screenshot of the working example's UI":::
230
225
231
-
232
226
## Fix and iterate upon the generated code
233
227
234
228
If the output that you receive from Copilot doesn't satisfy the stated requirements, one option is to reiterate your original instructions with more precise instructions, and instruct Copilot to "Continue updating" the code to meet the unmet requirements:
@@ -243,26 +237,22 @@ Continue updating #MainWindow.xaml and #MainWindow.xaml.cs to build a chat inter
243
237
5. When I click the Send button, display the input text in a TextBlock, and update the ProgressBar to indicate that the app is waiting for a response. Mock the code that generates a response with a delay of 2 seconds, and then display a response that echoes the input text above the input.
244
238
6. Ensure that **TextBlock** text wraps to the next line when it reaches the edge of the window.
245
239
246
-
Remove extraneous code as-needed. Directly modify the existing files. Do not explain yourself. Do not generate new files. Ensure that every single numbered requirement is accounted for in the end result. Ensure that both the markup and codebehind files are updated to produce a fully functional chat interface that builds and meets the above-stated requirements. Take your time. Reveal only two code blocks representing the end result, one for each file.
240
+
Remove extraneous code as-needed. Directly modify the existing files. Do not explain yourself. Do not generate new files. Ensure that every single numbered requirement is accounted for in the end result. Ensure that both the markup and code-behind files are updated to produce a fully functional chat interface that builds and meets the above-stated requirements. Take your time. Reveal only two code blocks representing the end result, one for each file.
247
241
```
248
242
249
-
Alternatively, you can use **multi-shot prompting** to break your problem down into smaller requirements, and then work on one at a time, incrementally building towards your desired outcome. This approach can be useful when you're not sure how to articulate your requirements with a high degree of technical precision, or when Copilot is struggling to generate the code you're looking for.
250
-
243
+
Alternatively, you can use **multi-shot prompting** to break your problem down into smaller requirements, and then work on one at a time, incrementally building towards your desired outcome. This approach can be useful when you're not sure how to articulate your requirements with a high degree of technical precision, or when Copilot is struggling to generate the code you want.
251
244
252
245
## Recap
253
246
254
247
In this how-to, we:
255
248
256
-
- Demonstrated how to streamline your WinUI 3 / Windows App SDK development workflow with GitHub Copilot Chat in Visual Studio
257
-
- Prompted Copilot to generate code that meets your requirements
258
-
- Highlighted the importance of providing Copilot with precise requirements to generate the code you're looking for
259
-
- Identified a variety of prompting techniques and use-cases for each
260
-
249
+
- Demonstrated how to streamline your WinUI 3 / Windows App SDK development workflow with GitHub Copilot Chat in Visual Studio
250
+
- Prompted Copilot to generate code that meets your requirements
251
+
- Highlighted the importance of providing Copilot with precise requirements to generate the code you want
252
+
- Identified a variety of prompting techniques and use-cases for each
261
253
262
-
## Related
254
+
## Related content
263
255
264
256
-[Sample applications for Windows development](../get-started/samples.md)
0 commit comments