Skip to content

Commit 9005874

Browse files
committed
Update lab docs for Copilot Agent and usability improvements
Enhanced documentation across multiple lab sections to improve clarity, usability, and alignment with the latest GitHub Copilot features: - Updated `copilot-instructions.md` to use `Configuration["ImagePrefix"]`. - Added a banner image and updated the lab title in `README.md`. - Renamed "Copilot Edits" to "Copilot Agent" and updated related instructions. - Improved step-by-step guides in `part0` through `part8` with additional details, images, and examples. - Streamlined the setup process in `setup.md` with detailed instructions for signing in, cloning the repository, and starting the app. - Added or updated supporting binary image files for better visualization. These changes aim to enhance the user experience and ensure the documentation reflects the latest capabilities of GitHub Copilot.
2 parents 1af2faf + 6b20249 commit 9005874

18 files changed

Lines changed: 253 additions & 130 deletions

.github/copilot-instructions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
- CSS should be in .razor.css files.
1414

1515
## Misc
16-
- To display an image you will always need to use `ImagePrefix` in the web front end which comes from the environment variables.
17-
- Ignore all *.md files code in the **lab** folder when making code suggestions.
16+
- To display an image you will always need to use `ImagePrefix` in the web front end which comes from the Configuration["ImagePrefix"] which isc @inject IConfiguration Configuration
17+
- Ignore all *.md files code in the **lab** folder when making code suggestions.

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<p align="center">
2+
<img src="img/banner.jpg" alt="decorative banner" width="1200"/>
3+
</p>
4+
15
# LAB300 - Hands-on with GitHub Copilot in Visual Studio 2022
26

37
This lab will guide you through using GitHub Copilot's various features in Visual Studio 2022. You'll start with a partially completed TinyShop application and use GitHub Copilot to complete missing features and enhance the application.
@@ -36,9 +40,16 @@ You'll use GitHub Copilot's various features to enhance and complete this applic
3640
3. [Enhancing UI with Inline Chat](lab/part2-enhancing-ui.md)
3741
4. [Referencing Code Files in Chat](lab/part3-referencing-files.md)
3842
5. [Using Custom Instructions](lab/part4-custom-instructions.md)
39-
6. [Implementing Features with Copilot Edits](lab/part5-implementing-features.md)
43+
6. [Implementing Features with Copilot Agent](lab/part5-implementing-features.md)
4044
7. [Using Copilot Vision](lab/part6-copilot-vision.md)
4145
8. [Debugging with Copilot](lab/part7-debugging-with-copilot.md)
4246
9. [Commit Summary Descriptions](lab/part8-commit-summary-descriptions.md)
4347

4448
**Key Takeaway**: These tools can significantly boost your productivity as a developer by automating repetitive tasks, generating boilerplate code, and helping you implement complex features more quickly.
49+
50+
## Session Resources
51+
52+
| Resources | Links | Description |
53+
|:-------------------|:----------------------------------|:-------------------|
54+
| Build session page | https://build.microsoft.com/sessions/LAB300 | Event session page with downloadable recording, slides, resources, and speaker bio |
55+
|Microsoft Learn|https://aka.ms/AAI_DevAppGitHubCop_Plan|Official Collection or Plan with skilling resources to learn at your own pace|

img/banner.jpg

97.1 KB
Loading

lab/images/1-agent.png

17.5 KB
Loading

lab/images/1-open-copilot-chat.png

500 Bytes
Loading

lab/images/3-chat.png

15.6 KB
Loading

lab/images/5-new-edits.png

10.8 KB
Loading

lab/images/5-select-sonnet.png

26.2 KB
Loading

lab/part0-exploring-codebase.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
GitHub Copilot Chat allows you to ask questions about your code and get intelligent responses.
44

5-
1. [] Open the solution in Visual Studio 2022.
6-
2. Click on the Github Copilot Chat in the top-right corner of Visual Studio and select **Open Chat Window** or press `Ctrl+\+C` if Copilot chat isn't open.
7-
5+
1. [] Open the solution in Visual Studio 2022 if it is not already open.
6+
1. Click on the Github Copilot Chat in the top-right corner of Visual Studio and select **Open Chat Window** or press `Ctrl+\+C` if Copilot chat isn't open.
87
![Open chat window dialog](./images/1-open-copilot-chat.png)
9-
10-
3. [] Try asking questions about the project structure:
8+
1. [] Try asking questions about the project structure:
119
- `What projects are in this solution and how do things work together?`
12-
- `What is the TinyShop application architecture?`
1310
- `How does the Products API work?`
14-
4. [] Notice how Copilot analyzes your codebase to provide contextual answers.
11+
1. [] Notice how Copilot analyzes your codebase to provide contextual answers.
1512

1613
**Key Takeaway**: GitHub Copilot Chat helps you understand unfamiliar codebases by answering questions about the project structure, architecture, and implementation details.

lab/part1-code-completion.md

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,40 @@
22

33
In this section, you'll use GitHub Copilot's code completion to implement API endpoints.
44

5-
> [!IMPORTANT]
6-
> For this exercise, **DO NOT** copy and paste the code snippet provided, but rather type it manually. This will allow you to experience code completion as you would if you were coding back at your desk. You'll likely see you only have to type a few characters before GitHub Copilot begins suggesting the rest.
5+
> IMPORTANT: For this exercise, **DO NOT** copy and paste the code snippet provided, but rather type it manually. This will allow you to experience code completion as you would if you were coding back at your desk. You'll likely see you only have to type a few characters before GitHub Copilot begins suggesting the rest.
76
8-
1. [] Open **ProductEndpoints.cs** in the Products project under **Endpoints** - it should be empty or contain minimal code.
9-
2. [] Begin typing a comment to describe what you want to implement:
7+
1. [] Stop debugging the appliaction if it is currently running.
8+
9+
1. [] In the Solution Explorer, in the **Products** project, open **Endpoints/ProductEndpoints.cs** - it will have a single endpoint implemented.
10+
11+
> Note: GitHub Copilot will not give code suggestions when debugging.
12+
13+
1. [] Let's implement a new **MapGet** to get product details for a specific **id**. Move our cursor and click on line 20 under the existing **/** endpoint. Text suggestion may apprear or type:
1014
```csharp
11-
group.MapGet(
15+
g
1216
```
13-
3. [] Wait for the ghost text suggestions to appear (gray text).
14-
17+
1. [] Wait for the ghost text suggestions to appear (gray text).
18+
;
1519
![Code suggestions](./images/1-ghost-text.png)
1620

17-
4. [] Press Tab to accept the suggestion or continue typing to get more specific suggestions.
21+
1. [] Press Tab to accept the suggestion or continue typing to get more specific suggestions.
1822

19-
5. [] From there Next Edit Suggetions (NES) or addtional Ghost Text suggestions will appear.
23+
1. [] From there Next Edit Suggetions (NES) or addtional Ghost Text suggestions will appear.
2024

2125
![NES showing up](./images/1-nes.png)
2226

23-
6. [] Implement the following endpoints using GitHub Copilot's suggestions:
24-
- GET product by ID
27+
1. [] We now can implement the following endpoints using GitHub Copilot:
2528
- POST to create a new product
2629
- PUT to update a product
2730
- DELETE to remove a product
2831

29-
The end code sould look similar to:
32+
- We can continue to use suggestions OR we could open GitHub Copilot Chat and work with Agent mode:
33+
- Open GitHub Copilot Chat in the top-right corner of Visual Studio and select **Open Chat Window** or press `Ctrl+\+C` if Copilot chat isn't open.
34+
- Switch to **Agent** mode.
35+
- ![Switch to agent mode](./images/1-agent.png)]
36+
- Ask the agent: `Can you implement the rest of the endpoints for the Product API and also implement the ProductService to call these new endpoints in the Store project?`
37+
38+
The end code in **ProductEndpoints.cs** sould look similar to:
3039

3140
```csharp
3241
group.MapGet("/", async (ProductDataContext db) =>
@@ -88,20 +97,83 @@ In this section, you'll use GitHub Copilot's code completion to implement API en
8897
.Produces(StatusCodes.Status404NotFound);
8998
```
9099

91-
> [!IMPORTANT]
92-
>Because LLMs are probabilistic, not deterministic, the exact code generated can vary. The above is a representative example. If your code is different, that's just fine as long as it works!
100+
In the **Store** project in the solution explorer open **Services/ProductService.cs**, the code sould look similar to:
93101

94-
7. [] Try changing the variable name of **id** to `productId` in the new **MapGet** method and see Next Edit Suggestions help out.
102+
```cs
103+
using DataEntities;
104+
using System.Text.Json;
105+
106+
namespace Store.Services;
107+
108+
public class ProductService
109+
{
110+
HttpClient httpClient;
111+
public ProductService(HttpClient httpClient)
112+
{
113+
this.httpClient = httpClient;
114+
}
115+
public async Task<List<Product>> GetProducts()
116+
{
117+
List<Product>? products = null;
118+
var response = await httpClient.GetAsync("/api/Product");
119+
if (response.IsSuccessStatusCode)
120+
{
121+
var options = new JsonSerializerOptions
122+
{
123+
PropertyNameCaseInsensitive = true
124+
};
125+
126+
products = await response.Content.ReadFromJsonAsync(ProductSerializerContext.Default.ListProduct);
127+
}
128+
129+
return products ?? new List<Product>();
130+
}
131+
132+
public async Task<Product?> GetProductById(int id)
133+
{
134+
var response = await httpClient.GetAsync($"/api/Product/{id}");
135+
if (response.IsSuccessStatusCode)
136+
{
137+
return await response.Content.ReadFromJsonAsync<Product>(ProductSerializerContext.Default.Product);
138+
}
139+
return null;
140+
}
141+
142+
public async Task<bool> CreateProduct(Product product)
143+
{
144+
var response = await httpClient.PostAsJsonAsync("/api/Product", product, ProductSerializerContext.Default.Product);
145+
return response.IsSuccessStatusCode;
146+
}
147+
148+
public async Task<bool> UpdateProduct(int id, Product product)
149+
{
150+
var response = await httpClient.PutAsJsonAsync($"/api/Product/{id}", product, ProductSerializerContext.Default.Product);
151+
return response.IsSuccessStatusCode;
152+
}
153+
154+
public async Task<bool> DeleteProduct(int id)
155+
{
156+
var response = await httpClient.DeleteAsync($"/api/Product/{id}");
157+
return response.IsSuccessStatusCode;
158+
}
159+
}
160+
```
161+
162+
> NOTE: Because LLMs are probabilistic, not deterministic, the exact code generated can vary. The above is a representative example. If your code is different, that's just fine as long as it works!
163+
164+
1. [] Go back to **ProductEndpoints.cs**, and try changing the variable name of **id** to `productId` in the new **MapGet** method and see Next Edit Suggestions help out.
95165

96166
![NES suggestions more](./images/1-nes-2.png)
97167

98-
8. [] Try using documentation generation:
168+
1. [] Try using documentation generation:
99169
- Type `///` above a method to generate XML documentation on the **MapProductEndpoints** this can also be brought up with `Alt+/` for inline and then entering **/** which will bring up a list of commands.
100170

101171
![documentation generation by Copilot](./images/1-docs.png)
102172

103-
9. [] Test your implementation:
173+
1. [] Test your implementation:
104174
- Run the AppHost project.
105-
- Test your new endpoints.
175+
- Test your new endpoints by going to **https://localhost:7130/api/Product/1**
176+
177+
1. [] Stop debugging and close the application
106178

107179
**Key Takeaway**: GitHub Copilot can generate complete API implementations based on your comments or partial code, significantly speeding up development.

0 commit comments

Comments
 (0)