In this lab exercise, you will set up a new C# Console App using GitHub Copilot. This Console App will be enhanced in subsequent steps to build a Music Store application.
-
Access GitHub Copilot:
-
Open the Chat Window:
- Click the chat icon in the activity bar or press
Control+Command+I
(Mac) /Ctrl+Alt+I
(Windows/Linux).
- Click the chat icon in the activity bar or press
-
Start an Inline Chat:
- Use
Ctrl+I
(Windows) orCmd+I
(Mac) to start an inline chat directly in the editor.
- Use
-
Quick Chat Dropdown:
- Open the quick chat dropdown by pressing
Shift+Command+I
(Mac) /Shift+Ctrl+I
(Windows/Linux).
- Open the quick chat dropdown by pressing
-
-
Create a New C# Console App:
- Use Copilot chat to create a new C# Console App.
- Type the following command to scaffold a new C# Console App. Try below prompt, the
@workspace
and/new
should be automatically highlighted.
@workspace /new Create a C# console application with project name as MusicStore.csproj and a solution file as MusicStore.sln, outputs an executable file. Use TargetFramework as net8.0.
Tip: GitHub Copilot provides various slash commands to avoid writing complex prompts for common scenarios. The
/new
command is particularly useful as it creates a new project based on the specified template. In this case, Copilot generates a new C# Console App named "MusicStore". Try also specifying more details in your prompt, like the target framework, project type, etc., to customize the project creation.- Click on the
Create Workspace
button to set up the project. This will create a new folder named "MusicStore" in your current workspace with the C# Console App project files.
- Inspect the .csproj file and ensure it targets net8.0. You can edit the text directly. Copilot is a great tool to help you write code, but it is not perfect. It is always a good idea to review the code and make sure it meets your requirements.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net8.0</TargetFramework> </PropertyGroup> </Project>
-
Run Your Application:
-
From the terminal, navigate to the "MusicStore" folder (that contains MusicStore.csproj file) and run the following command:
dotnet run
-
The console app should run successfully and load the console window with the default output.
Try asking Copilot for instructions on how to run the application using
@workspace
Chat participant. The@workspace
chat participant has context about the code in your workspace and allows you to ask questions or get help related to the code. -
Previous - Home | Next - Step 2: Building the Music Store Application