{"id":36750440,"url":"https://github.com/octodemo/csharp-copilot-workshop","last_synced_at":"2026-01-12T12:43:36.508Z","repository":{"id":227076373,"uuid":"770373366","full_name":"octodemo/csharp-copilot-workshop","owner":"octodemo","description":"GitHub Copilot workshop building a c# app from scratch - showcasing different use cases of Copilot such as code refactoring, code documentation, project scaffolding, unit test generation, Copilot Chat and more. ","archived":false,"fork":false,"pushed_at":"2024-03-12T07:02:58.000Z","size":580,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-03-12T14:11:52.932Z","etag":null,"topics":["copilot","csharp","workshop"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/octodemo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-11T12:48:13.000Z","updated_at":"2024-03-12T07:07:22.000Z","dependencies_parsed_at":"2024-03-11T14:18:33.529Z","dependency_job_id":null,"html_url":"https://github.com/octodemo/csharp-copilot-workshop","commit_stats":null,"previous_names":["octodemo/csharp-copilot-workshop"],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/octodemo/csharp-copilot-workshop","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octodemo%2Fcsharp-copilot-workshop","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octodemo%2Fcsharp-copilot-workshop/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octodemo%2Fcsharp-copilot-workshop/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octodemo%2Fcsharp-copilot-workshop/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/octodemo","download_url":"https://codeload.github.com/octodemo/csharp-copilot-workshop/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/octodemo%2Fcsharp-copilot-workshop/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28338983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["copilot","csharp","workshop"],"created_at":"2026-01-12T12:43:35.731Z","updated_at":"2026-01-12T12:43:36.485Z","avatar_url":"https://github.com/octodemo.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# C# Project Workshop with GitHub Copilot\n\nWelcome to this interactive workshop where we will use GitHub Copilot to create a C# project with CRUD operations. This project will allow us to add, update, and delete users. We will work through multiple different use-cases of GitHub Copilot. \n\n## Getting Started\n\n### Launch IDE \nStart by launching your Codespace environment or IDE of your choice in which GitHub Copilot is supported (Visual Studio, VS Code, GitHub Codespaces, Neovim and JetBrains). **Note:** This workshop relies heavily on Copilot Chat which may not be available in all IDEs -- however, you may still follow along and prompt GitHub Copilot inline using comments rather than using chat. \n\n### Familiarize Yourself with the Project Directory\nTake a moment to explore the project directory. (Surprise! It's empty)\n\n### Install Copilot Extension\nNavigate to the extensions tab on the left hand side of the codespace. Search 'copilot' and install the GitHub Copilot extension. Note that this will also install the chat feature. If using a different IDE, navigate to the marketplace and search for `copilot`. \n\n\u003cimg src=\"./images/copilot_extension.png\" alt=\"GitHub Copilot Extension\" width=\"250\"/\u003e\n\n#### Authenticate to the GitHub Copilot Service\nDepending on which IDE you are using, you will be prompted to login with your GitHub credentials. \n\n\n### Open Copilot Chat\nOpen up the chat feature and say hello to Copilot!\n\n### Explore Built-in Commands\nGitHub Copilot chat includes built-in commands (hotkeys) for common tasks. You can explore these using the `/` command in chat.\n\n## Creating a New Workspace\n\n### Create a New Workspace\nStart typing `new` in the chat and choose the `new workspace` option. Ask Copilot to `scaffold a new C# project`. Copilot will create a new workspace and present you with a convenient button to create the workspace for you. Click this button, name the workspace `my-csharp-project` (see second image below) and wait for the Codespace to reload. (see image below)\n\n\u003cimg src=\"./images/new_workspace.png\" alt=\"GitHub Copilot New Workspace Command\" width=\"250\"/\u003e\n\n\n\u003cimg src=\"./images/workspace_name3.png\" alt=\"GitHub Copilot New Workspace Command\" width=\"600\"/\u003e\n\n\n\n### Explore the New Project\nOnce the Codespace has reloaded, familiarize yourself with the contents of the new project and its directories.\n\n## Building the Application\nWe will use Copilot in the IDE to create a `User` class with `ID`, `Name`, and `Email` properties, along with their respective `get` and `set` methods.\n\n\n### Create a User Class\n\nWe will use Copilot in the IDE to create a `User` class with `ID`, `Name`, and `Email` properties, along with their respective `get` and `set` methods.\n\nNavigate to the `/src/Classes` directory and create a new file called `User.cs` (**Note:** If there is no /src/Classes directory, create one). \n\nAt the top, we will write a comment to prompt GitHub Copilot:\n\n```csharp\n// setup a class called User with 3 properties: Id, Name, and Email\n// The properties are defined using the get and set accessors.\n// Use the appropriate namespace for the project (MyCSharpProject.Classes).\n// The set accessor assigns a new value to the property, and the get accessor returns the property value.\n```\n\nThe contents returned should be something along the lines of:\n\n```csharp\nusing System;\n\nnamespace MyCSharpProject.Classes\n{ \n    public class User\n    {\n        public int Id { get; set; }\n        public string Name { get; set; }\n        public string Email { get; set; }\n    }\n}\n```\n\nAlternatively, you may begin typing into the file the solution above, and see what suggestions Copilot returns along the way. \n\n### Create a User Service\nWe will ask **Copilot chat** to create the `UserService`. This service will handle the CRUD operations for our `User` objects.\n\nNavigate to the `/src/Classes` directory and create a new file called `UserService.cs`. We will use GitHub Copilot chat to generate the contents of this service file. \nIn the chat interface, prompt copilot to \n\n```csharp \n// We are creating a simple C# console application that performs basic CRUD operations on a list of users. Create a UserService class in the MyCSharpProject.Classes namespace that manages a list of User objects. The User class has properties Id, Name, and Email. The UserService class should have methods to add a user, get a user by id, update a user's details, and delete a user by id.\n```\n\n\nThe response should contain code similar to the following solution below: \n\n```csharp\nusing System.Collections.Generic;\nusing System.Linq;\nnamespace MyCSharpProject.Classes{ \npublic class UserService\n{\n    private List\u003cUser\u003e users = new List\u003cUser\u003e();\n\n    public void AddUser(User user)\n    {\n        users.Add(user);\n    }\n\n    public User GetUser(int id)\n    {\n        return users.FirstOrDefault(u =\u003e u.Id == id);\n    }\n\n    public void UpdateUser(User user)\n    {\n        var existingUser = GetUser(user.Id);\n        if (existingUser != null)\n        {\n            existingUser.Name = user.Name;\n            existingUser.Email = user.Email;\n        }\n    }\n\n    public void DeleteUser(int id)\n    {\n        var user = GetUser(id);\n        if (user != null)\n        {\n            users.Remove(user);\n        }\n    }\n}\n}\n```\nUse the built-in `insert` button (see below) in the chat response interface to insert at the cursor in your `UserService.cs` file. \n\n\u003cimg src=\"./images/copilot_insert.png\" alt=\"GitHub Copilot Insert\" width=\"250\"/\u003e\n\n### Create the Entry Point\nNavigate to the `Program.cs` file (in the root directory) and use Copilot chat to create the entry point for our project.\n\n```csharp \n// This file contains the Main method where you create an instance of UserService and perform operations like adding, getting, updating, and deleting users. \n// create a main program that uses the UserService class to add, get, update, and delete a User. The User class has properties Id, Name, and Email. The UserService class has methods to add a user, get a user by id, update a user's details, and delete a user by id. Demonstrate these operations in the Main method.\n```\nThe response should contain code similar to the following solution below: \n\n```csharp \nusing System;\nusing MyCSharpProject.Classes;\n\npublic class Program\n{\n    static void Main(string[] args)\n    {\n        UserService userService = new UserService();\n\n        // Add a user\n        userService.AddUser(new User { Id = 1, Name = \"John Doe\", Email = \"john.doe@example.com\" });\n\n        // Get a user\n        User user = userService.GetUser(1);\n        Console.WriteLine($\"Got user: {user.Name}\");\n\n        // Update a user\n        user.Name = \"Jane Doe\";\n        userService.UpdateUser(user);\n\n        // Delete a user\n        userService.DeleteUser(1);\n    }\n}\n```\nUse the built-in `insert` button (see below) in the chat response interface to insert at the cursor in your `UserService.cs` file. \n\n\u003cimg src=\"./images/copilot_insert.png\" alt=\"GitHub Copilot Insert\" width=\"250\"/\u003e\n\n### Add additional users\nUse Copilot to add additional users in the `Program.cs` file. \n\n### Review the Code\nAnother use case for GitHub Copilot chat is code review. For an extra set of eyes, you may highlight the contents of each of the three files and ask Copilot to review them for syntax errors or any other issues.\n\nAlternatively, you may use the built-in `/workspace` command and ask Copilot chat to check the contents of specific files for errors (see image below):\n\n\u003cimg src=\"./images/workspace_check.png\" alt=\"GitHub Copilot Insert\" width=\"250\"/\u003e\n\n#### Document existing code\nCopilot Chat can be leverage to document existing codebases. Highlight the contents of the `UserService.cs` file (or any file of your choice) and ask Copilot Chat to `modify this file in order to include documentation in the form of inline comments`. Review the response and notice how Copilot can aide in documenting existing codebases - making it much easier for developers to understand how to navigate complex and unfamiliar codebases. \n\n### Generate the .csproj File\nNavigate to your `.csproj` file in the `/src` directory - if it doesn't have one already, create the file and name it based on your project name, ie: `MyCSharpProject.csproj`. Navigate to Copilot Chat to generate the contents for the `.csproj` file. Ask Copilot to use .NET version 7 and to include the appropriate `ItemGroup` elements.\n\n```csharp \n// Create a .NET project file that targets .NET 7.0, outputs an executable, and includes Program.cs and all C# files in the Classes directory\n```\n\nThe response should contain code similar to the following solution below: \n\n```\n\u003cProject Sdk=\"Microsoft.NET.Sdk\"\u003e\n\n    \u003cPropertyGroup\u003e\n        \u003cOutputType\u003eExe\u003c/OutputType\u003e\n        \u003cTargetFramework\u003enet7.0\u003c/TargetFramework\u003e\n        \u003cEnableDefaultCompileItems\u003efalse\u003c/EnableDefaultCompileItems\u003e\n    \u003c/PropertyGroup\u003e\n\n    \u003cItemGroup\u003e\n        \u003cCompile Include=\"Program.cs\" /\u003e\n        \u003cCompile Include=\"Classes/*.cs\" /\u003e\n    \u003c/ItemGroup\u003e\n\n\u003c/Project\u003e\n```\n\n## Running the Application\n\n### Build the Project\nNow we're ready to build the project. Navigate to the `/src` directory via the terminal and run `dotnet build`. If you run into any errors, copy and paste the contents of the error into Copilot chat and use it as an aide to guide you towards a fix. \n\n### Run the Application\nUse `dotnet run` to run the application.\n\n## Testing and Debugging\n\n### Generate Tests\nUse Copilot to generate tests for your application. Test files are located in the `/tests` directory.\n\nCreate a test file and name it `UserServiceTests.cs` - this should be created in the `/tests/MyCSharpProject.Tests` directory. Ask Copilot Chat to `generate unit tests for the addUser, getUserById, deleteUser and updateUser methods in the UserService.cs file` - you'll want to review the output and modify accordingly to ensure the appropriate function names are being used. \n\nAlternatively, you may generate the unit tests one method at a time, using inline comments to prompt Copilot. Begin typing the following and press enter to see Copilots suggestions. Sometimes, you will need to hit enter twice (to have a new line) in order to generate suggestions for the next block of code. \n\n```csharp\n//create a test method for the add user method in the UserService.cs file\n```\n\nReview the response provided by Copilot, accept the suggestions and edit as necessary.\n\nOnce the first test is created, you'll notice that if you have a new line between the previous chunk of code, Copilot should begin to prompt for additional tests (see image below):\n\n\u003cimg src=\"./images/copilot_autofill_suggestion.png\" alt=\"GitHub Copilot Insert\" width=\"600\"/\u003e\n\nRun through and create a few different tests. Below is a sample output -- keep in mind your solution will look a bit different.\n\n```csharp\nusing System;\nusing Microsoft.VisualStudio.TestTools.UnitTesting;\nusing MyCSharpProject.Classes;\n\n\nnamespace MyCSharpProject.Tests\n{\n    [TestClass]\n    public class UserServiceTests\n    {\n        //create a test method for the add user method in the UserService.cs file\n        [TestMethod]\n        public void TestAddUser()\n        {\n            // Arrange\n            int id = 1;\n            string name = \"Test User\";\n            string email = \"testuser@example.com\";\n\n            // Act\n            User user = new User { Id = id, Name = name, Email = email };\n\n\n            // Assert\n            Assert.AreEqual(id, user.Id);\n            Assert.AreEqual(name, user.Name);\n            Assert.AreEqual(email, user.Email);\n\n\n        }\n\n\n        //create a test method for the get user by id method in the UserService.cs file\n        [TestMethod]\n        public void TestGetUserById()\n        {\n            // Arrange\n            UserService userService = new UserService();\n            User user = new User { Id = 1, Name = \"Test User\", Email = \"testemail@example.com\" };\n            userService.AddUser(user);\n\n            // Act\n            User retrievedUser = userService.GetUserById(1);\n\n            // Assert\n            Assert.AreEqual(user.Id, retrievedUser.Id);\n            Assert.AreEqual(user.Name, retrievedUser.Name);\n            Assert.AreEqual(user.Email, retrievedUser.Email);\n        }\n\n        //create a test method for the update user method in the UserService.cs file\n        [TestMethod]\n        public void TestUpdateUser()\n        {\n            // Arrange\n            UserService userService = new UserService();\n            User user = new User { Id = 1, Name = \"Test User\", Email = \"testuser@example.com\" };\n            userService.AddUser(user);\n            User updatedUser = new User { Id = 1, Name = \"Test User\", Email = \"newemail@example.com\" };\n\n            // Act\n            userService.UpdateUser(updatedUser);\n            User retrievedUser = userService.GetUserById(1);\n\n            // Assert\n            Assert.AreEqual(updatedUser.Email, retrievedUser.Email);\n        }\n\n        //create a test method for the delete user method in the UserService.cs file\n        [TestMethod]\n        public void TestDeleteUser()\n        {\n            // Arrange\n            UserService userService = new UserService();\n            User user = new User { Id = 1, Name = \"Test User\", Email = \"testuser@example.com\" };\n            userService.AddUser(user);\n\n            // Act\n            userService.DeleteUser(1);\n\n            // Assert\n            Assert.ThrowsException\u003cException\u003e(() =\u003e userService.GetUserById(1));\n\n\n}\n    }\n}\n```\n\n#### Generate .csproj file for tests\nIf there's no `.csproj` file in the `tests/MyCSharpProject.Tests` directory, you'll need to create one. Ask Copilot Chat to fill in the contents of this file. Below is a sample output:\n\n```\n\u003cProject Sdk=\"Microsoft.NET.Sdk\"\u003e\n\n    \u003cPropertyGroup\u003e\n        \u003cTargetFramework\u003enet7.0\u003c/TargetFramework\u003e\n    \u003c/PropertyGroup\u003e\n\n    \u003cItemGroup\u003e\n        \u003cPackageReference Include=\"Microsoft.NET.Test.Sdk\" Version=\"17.0.0\" /\u003e\n        \u003cPackageReference Include=\"MSTest.TestAdapter\" Version=\"2.2.7\" /\u003e\n        \u003cPackageReference Include=\"MSTest.TestFramework\" Version=\"2.2.7\" /\u003e\n    \u003c/ItemGroup\u003e\n\n    \u003cItemGroup\u003e\n        \u003cProjectReference Include=\"..\\..\\src\\MyCSharpProject.csproj\" /\u003e\n    \u003c/ItemGroup\u003e\n\n\u003c/Project\u003e\n```\n\n#### Run tests\nEnsure you are in the `/tests/MyCSharpProject.Tests` directory. Open up terminal and navigate to `/tests/MyCSharpProject.Tests` and run the command `dotnet test`. \n\n### Debugging\nIf you run into errors, you can use Copilot chat to assist you. Consider using the built-in `/fix` command.\n\n---\n\nEnjoy the workshop and happy coding!\n\n# Challenge Exercises\n\n## Intermediate\n\n- Refractor code using GitHub Copilot Chat - highlight the contents of the `UserService.cs` file and ask Copilot Chat `refractor this code snippet` - notice the output suggested by Copilot. \n- Modify the methods in UserService.cs to update a user's name or email address (updateEmail or updateName) \n- Modify the GetUser method to support pagination\n- Create a method to assign roles to a user\n- Create a method to search for users by name\n- Create a method to log events in the application\n- Create an API controller for the User class\n- Create unit tests for the UpdateUser method\n- Create unit tests for the getUser method\n- Create unit tests for the addUser method\n- Modify code to handle errors/exceptions  \n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctodemo%2Fcsharp-copilot-workshop","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foctodemo%2Fcsharp-copilot-workshop","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foctodemo%2Fcsharp-copilot-workshop/lists"}