Skip to content

Commit 0dc4fa8

Browse files
committed
Merged main into live
2 parents fb784e1 + f8cf533 commit 0dc4fa8

File tree

4 files changed

+50
-69
lines changed

4 files changed

+50
-69
lines changed

hub/apps/how-tos/copilot-chat-winui3.md

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
---
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.
4+
ms.topic: how-to
5+
ms.date: 11/26/2024
6+
keywords: windows app sdk, winappsdk, winui3, openai, chatgpt, copilot, github copilot
77
ms.localizationpriority: medium
8-
ms.custom: template-quickstart
98
audience: new-desktop-app-developers
10-
content-type: how-to
9+
#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.
1110
---
1211

1312
# Streamline your WinUI 3 / Windows App SDK development workflow with GitHub Copilot Chat
1413

1514
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.
1615

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.
1817

1918
## Prerequisites
2019

2120
- Visual Studio 2022 [version 17.8](/visualstudio/releases/2022/release-history) or later
2221
- 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.
2322
- [**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.
2725

2826
## Prompting techniques
2927

@@ -33,9 +31,9 @@ The goal of this how-to is to equip you with **vocabulary** and **prompting tech
3331

3432
In Visual Studio, select **View > GitHub Copilot Chat**.
3533

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.":::
3735

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.
3937

4038
### Prompting through inline Copilot Chat
4139

@@ -45,7 +43,6 @@ From any file's editor window, right click and select Ask Copilot to bring up th
4543

4644
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.
4745

48-
4946
## Create a new WinUI 3 project
5047

5148
Type the following into the Copilot Chat window:
@@ -60,7 +57,6 @@ You should see instructions appear:
6057

6158
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.
6259

63-
6460
## Display a "Hello, world!" message
6561

6662
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
8581

8682
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:
8783

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":::
8985

9086
:::image type="content" source="images/copilot-chat/5-preview-markup.png" alt-text="Screenshot of the Preview button when working with the markup file":::
9187

@@ -104,14 +100,13 @@ What files should I change in my #Solution in order to achieve <desired outcome>
104100
Type the following into the Chat window:
105101

106102
```
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.
108104
```
109105

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:
111107

112108
:::image type="content" source="images/copilot-chat/6-results-hello-world.png" alt-text="Screenshot of the hello world results":::
113109

114-
115110
## Build the chat interface
116111

117112
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
126121
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.
127122
6. Ensure that **TextBlock** text wraps to the next line when it reaches the edge of the window.
128123
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.
130125
```
131126

132127
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
135130

136131
At the time of this writing, the above input generated the below output:
137132

138-
```MainWindow.xaml.cs
133+
```csharp MainWindow.xaml.cs
139134
using Microsoft.UI.Xaml;
140135
using Microsoft.UI.Xaml.Controls;
141136
using System;
@@ -184,7 +179,7 @@ namespace ImageGenerator
184179
}
185180
```
186181

187-
```MainWindow.xaml
182+
```xml MainWindow.xaml
188183
<Window
189184
x:Class="ImageGenerator.MainWindow"
190185
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -228,7 +223,6 @@ Which yielded the following UI:
228223

229224
:::image type="content" source="images/copilot-chat/7-working-example.png" alt-text="Screenshot of the working example's UI":::
230225

231-
232226
## Fix and iterate upon the generated code
233227

234228
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
243237
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.
244238
6. Ensure that **TextBlock** text wraps to the next line when it reaches the edge of the window.
245239
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.
247241
```
248242

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.
251244

252245
## Recap
253246

254247
In this how-to, we:
255248

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
261253

262-
## Related
254+
## Related content
263255

264256
- [Sample applications for Windows development](../get-started/samples.md)
265257
- [Windows developer FAQ](../get-started/windows-developer-faq.yml)
266-
- [Windows developer glossary](../get-started/windows-developer-glossary.md)
267258
- [Windows development best practices](../get-started/best-practices.md)
268-
- [How to target multiple platforms with your WinUI 3 app](uno-multiplatform.md)

0 commit comments

Comments
 (0)