This is a simplified version of the GitHub Copilot Hands-On Lab for quickly ramp-up GitHub Copilot. The original version is available at GitHub Copilot Hands-On Lab
- Config GitHub Copilot in you VS Code.
- Install the GitHub Copilot extension @id:github.copilot
- Install the GitHub Copilot Chat extension @id:GitHub.copilot-chat.
- Sign in with your GitHub Enterprise account.
- Install VS Code C# Dev Kit extension @id:ms-dotnettools.csdevkit
- Download the SampleApps for the hands-on lab https://raw.githubusercontent.com/xiaoliangshi/GitHubCopilotHandsOnLab/refs/heads/main/Lab_SampleApps.zip
-
Open the folder
APL2007M2Sample1with VS Code. -
Open Chat
Ctrl + Alt + i -
Type the prompt to explain the project.
@workspace Explain this project
-
Open the file
MainWindow.xaml.cs. -
Ask copilot to explain the file.
@workspace /explain #file:MainWindow.xaml.cs
-
In file
MainWindow.xaml.cs, locate the methodSumPageSizesAsync(), select the following code lines.IEnumerable<Task<int>> downloadTasksQuery = from url in _urlList select ProcessUrlAsync(url, _client); Task<int>[] downloadTasks = downloadTasksQuery.ToArray();
-
Right click to open the context menu
Copilot > Explain.
-
In file
MainWindow.xaml.cs, locate the methodSumPageSizesAsync(), select the following code line.int[] lengths = Task.WhenAll(downloadTasks);
-
Open inline chat
Ctrl + i, enter the prompt to ask for the error./explain why is the selection causing an error -
Right click to open the context menu
Copilot > Fix. Fix the error by changing the code to:int[] lengths = await Task.WhenAll(downloadTasks);
-
Open the folder
APL2007M2Sample1with VS Code. -
Open chat
Ctrl + Alt + i, enter the prompt to generate a README file.@workspace generate a readme document that can be used as a repo description
-
Open the file
MainWindow.xaml.cs. -
Select all the code lines.
-
Open chat
Ctrl + Alt + i, enter the prompt to generate a README file. Generate inline code documentation with copilot chat.@workspace generate inline code documentation for the selected code -
Select the code lines for the function
OnStartButtonClick, open inline edit withCtrl + iGenerate inline code documentation with inline chat/doc
- Open the folder
APL2007M4PrimeServicewith VS Code. - In the file
PrimeService.cs, locate the classPrimeService. - Add a comment above the class to generate the method
IsPrime.// Generate a method named IsPrime that takes an integer as input and returns a boolean indicating whether the number is prime or not.
- In the file
PrimeService.cs, locate the classPrimeService. - Add a method signature for the function
IsPrimewith the return typebooland input parameterint number.public bool IsPrime(int number)
- Open the file
PrimeService.cs - Open the GitHub Copilot chat
Ctrl + Alt + iGenerate a method named IsPrime that takes an integer as input and returns a boolean indicating whether the number is prime or not.
- Open the folder
APL2007M4PrimeServicewith VS Code. - Select the code lines for the function
IsPrime. - Open the GitHub Copilot chat
Ctrl + Atl + i, add contextPrimeService.UnitTests.csproj.andPrimeServiceTests.cs - Generate the unit test code with below prompt.
/tests add unit tests for my code - Build & Run the tests
- Curser to the function
IsPrime, Open the GitHub Copilot chatCtrl + i - Try the prompt below to generate unit tests.
Create unit tests for the IsPrime method using the xUnit framework.
- Open the GitHub Copilot chat
Ctrl + Atl + i - Try the prompt below to generate unit tests for specific cases.
@workspace are there any edge cases that should also be tested