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: Using-GitHub-Copilot-with-CSharp/README.md
+57-45Lines changed: 57 additions & 45 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,87 +43,99 @@ The "**GitHub Codespaces ♥️ .NET 8**" repository builds a Weather API using
43
43
We will review the steps to update the Weather BackEnd App by adding a new endpoint that requests a specific location and returns the weather forecast for that location.
44
44
45
45
46
-
### 🗒️ Step 1: Get familiarized with the "GitHub Codespaces ♥️ .NET 8" repository
46
+
### 🗒️ Section 1: Code Completion
47
47
48
-
Once you open the repository in Codespaces, you will find a new browser window with a fully functional Codespace. Everything in this repository is contained within this one Codespace.
49
-
This is a great opportunity to get started with GitHub Copilot Chat right away! We have opened up a new repository and we want to get familiar with it. Navigate to the top of the GitHub Codespace and select the Copilot Chat icon to the right search bar:
48
+
🎯**Learning Goals**
49
+
- Use inline code completion to scaffold new classes and methods
We can use the explorer panel to review the BackEnd and Front projects. Instead, let's use GitHub Copilot to get more familiar with this codebase. GitHub Copilot is designed to use natural language, but it also includes 'slash commands' that allow for a faster way to ask Copilot. In the chat pane, type in a '/' and see the different options available. If you type '/help' you can see the full list of commands available. You can also reference the [slash commands in the GitHub documentation.](https://docs.github.com/en/copilot/reference/github-copilot-chat-cheat-sheet#slash-commands)
54
-
55
-
Let's first understand our codebase. In the Chat pane type '/explain'. GitHub Copilot will explain how the project is structured, including the Frontend and Backend details.
53
+
Once your Codespace launches, you'll have a fully functional development environment with the entire repository preloaded. This is the perfect time to explore GitHub Copilot Chat to help you better understand the codebase.
56
54
57
-
TODO: Insert gif/video
58
-
59
-
To go a step further, I ask GitHub Copilot to create a diagram for the workflow of our application so I can better understand how it works together.
55
+
To get started:
60
56
57
+
1. Click the Copilot Chat icon in the top-right corner of the Codespace window
2. Instead of manually exploring the BackEnd and Front folders, try asking Copilot for an overview. In the chat pane, type '/' to view available slash commands — these offer quick, structured ways to interact with Copilot.
61
+
Type '/help' to see all commands, or check out the {GitHub Copilot Chat cheat sheet for a list of slash commands](https://docs.github.com/copilot/reference/github-copilot-chat-cheat-sheet#slash-commands) available.
62
+
For example, you can use:
63
+
-`/doc` to add a documentation comment
64
+
-`/explain` to explain the code
65
+
-`/fix` to propose a fix for the problems in the selected code
66
+
-`/generate` to generate code to answer your question
63
67
64
-
TODO: add the gif/screenshot
68
+
3. In lieu of using natural language, type in '/explain' into the chat pane. The output from GitHub Copilot will go into details of how the project is structured, including further information of the Frontend and Backend details.
65
69
70
+
TODO: Add gif/jpg of output
66
71
72
+
4. As a visual learner, you can ask GitHub Copilot to create a diagram of the workflow of the application. This could be saved into a README for further documentation.
67
73
74
+
TODO: Add gif/jpg of flow
68
75
76
+
5. Ask GitHub Copilot in the chat pane to "run and debug" the backend project (you can also do this from the 'run and debug' panel in the editor). Copilot will debug the selected project, showing the running port 8080. Copilot will give you the url to the website (selecting the 'ports' tab in the terminal will also output the url). When selecting the published url ensure that the '/weatherforecast' endpoint is named. This should produce a successfully test displaying the running application.
69
77
70
-
For example, in the explorer panel, we can see the main code for the BackEnd and the FrontEnd projects.
78
+
TODO: Add gig/jpg
71
79
72
-

80
+
In this section you learned how to use both natural language or slash commands to quickly understand the codebase without digging through folders. In the next set of exercises we're going to use Copilot to create a new class using code completion
73
81
74
-
In order to run the BackEnd project, go to the "Run and Debug" panel, and select the "BackEnd" Project.
82
+
6.In order to generate a new record that includes the name of the city, navigates to the following path `SampleApp\BackEnd\Program.cs`and open `Program.cs`. Navigate to the end of the file and type in (or copy):
75
83
76
-

84
+
```csharp
85
+
// create a new internal record named WeatherForecastByCity that request the following parameters: City, Date, TemperatureC, Summary
86
+
```
77
87
78
-
Start Debugging the selected project. The Weather API project, our BackEnd project will now be running in port 8080. We can copy the published url from the *Ports* panel
88
+
TODO: show output
79
89
80
-

90
+
7. We can create a new C# class by creating a new file under the 'BackEnd' folder: '/BackEnd/customer.cs'. Press `CTRL + I` to open the inline chat and type in:
91
+
92
+
```csharp
93
+
// Create a class for a Customer with Id, Name, and Email, and a method to validate email format
94
+
```
81
95
82
-
The BackEnd application published an endpoint named `weatherforecast` that generates random forecast data. To test the current running application, you can add `/weatherforecast` to the published url. The final url should be similar to this one
96
+
8. Accept the suggestion and using the inline prompt window ask:
83
97
84
-
```bash
85
-
https://< your url>.app.github.dev/weatherforecast
98
+
```csharp
99
+
/improveIsValidEmailmethodusingRegex
86
100
```
87
-
The running application in a browser should be like this one.
88
101
89
-

Now let's add a break point into our application, to debug each call to the API. Go to the `Program.cs` file in the BackEnd project. The file is in the following path `SampleApp\BackEnd\Program.cs`.
Add a breakpoint in line 24 (press F9) and refresh the browser with the Url to test the endpoint. The browser should not show the weather forecast, and in the Visual Studio Editor we can see how the program execution was paused at line 24.
106
+
TODO: Can'tgetrecordingofnexteditsonthisfile :(
94
107
95
-

Pressing F10 we can debug step-by-step until line 32, where we can see the generated values. The application should have generated samples Weather values for the next 5 days. The variable `forecast` has an array containing these values.
98
113
99
-

114
+
### 📄Section 2: GitHubCopilotAgentMode
100
115
101
-
You can stop debugging now.
116
+
🎯**LearningGoals**
117
+
- ObserveautonomouscodingandPRgeneration
118
+
- AssignissuestotheCopilotcodingagent
102
119
120
+
Inthissectionw
103
121
104
-
Congratulations! Now you are ready to add more features into the app using GitHub Copilot.
105
122
106
-
### 🗒️ Step 2: Get familiarized with GitHub Copilot Slash Commands
107
123
108
-
As we start working in our codebase, we usually need to refactor some code, or get more context or explanations about it. Using GitHub Copilot Chat, we can have AI-driven conversations to perform these tasks.
109
124
110
-
Open the file `Program.cs` in the BackEnd project. The file is in the following path `SampleApp\BackEnd\Program.cs`.
Now let's use a slash command, in GitHub Copilot to understand a piece of code. Select lines 22-35, press `CTRL + I` to open the inline chat, and type `/explain`.
In the Chat Panel, GitHub Copilot will create a detailed explanation of the selected code. A summarized version will be like this one:
117
137
118
-
```
119
-
The selected C# code is part of an ASP.NET Core application using the minimal API feature. It defines a GET endpoint at "/weatherforecast" that generates an array of WeatherForecast objects. Each object is created with a date, a random temperature, and a random summary. The endpoint is named "GetWeatherForecast" and has OpenAPI support for standardized API structure documentation.
120
-
```
121
138
122
-
**Slash commands** are special commands that you can use in chat to perform specific actions on your code. For example, you can use:
123
-
-`/doc` to add a documentation comment
124
-
-`/explain` to explain the code
125
-
-`/fix` to propose a fix for the problems in the selected code
126
-
-`/generate` to generate code to answer your question
0 commit comments