|
| 1 | +<!-- --- |
| 2 | +lab: |
| 3 | + title: 'Exercise - Install and configure GitHub Copilot' |
| 4 | + description: 'Learn how to install and configure GitHub Copilot in Visual Studio Code.' |
| 5 | +--- --> |
| 6 | + |
| 7 | +# Install and configure GitHub Copilot |
| 8 | + |
| 9 | +In this exercise you will <!-- provide a description of what they'll do and why it;s important --> |
| 10 | + |
| 11 | +This exercise should take approximately **15** minutes to complete. |
| 12 | + |
| 13 | +## Before you start |
| 14 | + |
| 15 | +Your development environment must include the following resources: |
| 16 | + |
| 17 | +- Git version control software. |
| 18 | +- The .NET SDK 9.0 (or the latest supported version). |
| 19 | +- Visual Studio Code updated to the latest version. |
| 20 | +- The C# Dev Kit extension (from Microsoft) installed in Visual Studio Code. |
| 21 | + |
| 22 | +Before you start this exercise, you need to: |
| 23 | + |
| 24 | +1. Verify that Git and the .NET SDK are available in your dev environment. If needed, you can download Git using the following URL: <a href="https://git-scm.com/downloads" target="_blank">Download Git</a> and the .NET SDK using the following URL: <a href="https://dotnet.microsoft.com/download/dotnet" target="_blank">Download .NET SDK</a> |
| 25 | +1. Verify that Visual Studio Code and the C# Dev Kit extension are available in your dev environment. You can download Visual Studio Code using the following URL: <a href="https://code.visualstudio.com/download" target="_blank">Download Visual Studio Code</a> and the C# Dev Kit extension using the following URL: <a href="https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp-devkit" target="_blank">C# Dev Kit</a>. |
| 26 | + |
| 27 | +For additional help configuring the Visual Studio Code environment, see <a href="https://learn.microsoft.com/training/modules/install-configure-visual-studio-code/" target="_blank">Install and configure Visual Studio Code for C# development</a> |
| 28 | + |
| 29 | +## Exercise scenario |
| 30 | + |
| 31 | +An accident damaged the servers that host the library database and backend services. It'll take weeks for administrators to obtain the funding/authorization required to replace the servers and get the system back online. Your department needs to develop a temporary solution that will enable librarians to perform basic functions. |
| 32 | + |
| 33 | +Your team has met with the librarians. They need a minimal solution that enables them to provide library patrons with essential services like book loans and returns. Your team investigates the available resources and develops a plan. Initially, only you and one other coworker will be assigned to the project. The local government has closed the library until your temporary solution is available. You have three days develop a v1 solution that enables the library to reopen. |
| 34 | + |
| 35 | +While your colleague begins working on the software, you use library records to create JSON files that represent the library's patron accounts, books, and book loans. By the end of the second day you're ready to begin helping with the code. The solution is a console application that can be run on one of the library's laptop computers. The librarians understand that there isn't time for a pretty interface, but stress that the app must be secure and reliable. You have one more day before you need to demonstrate version 1.0 of your app. |
| 36 | + |
| 37 | +You'll use GitHub Copilot to help get the work done as efficiently as possible. If all goes well, your app will be used to support the library's book drives and other offsite functions in the future. |
| 38 | + |
| 39 | +This exercise includes the following tasks: |
| 40 | + |
| 41 | +1. Install GitHub Copilot extensions for Visual Studio Code. |
| 42 | +1. Configure GitHub Copilot extensions for Visual Studio Code. |
| 43 | + |
| 44 | +## Install GitHub Copilot extensions for Visual Studio Code |
| 45 | + |
| 46 | +GitHub Copilot is an AI-powered code completion tool that helps developers write code faster and with fewer errors. The following subscription options are available: |
| 47 | + |
| 48 | +- GitHub Copilot Free: This free tier provides limited access to select features of GitHub Copilot, allowing an individual to experience AI-powered coding assistance without a paid subscription. The free tier currently includes 2000 code completions and 50 chat messages per month. |
| 49 | +- GitHub Copilot Pro: This paid tier is available to individual GitHub customers who don't have access to GitHub Copilot through an organization or enterprise. It offers full access to all GitHub Copilot features, including advanced capabilities and unlimited usage, for a comprehensive AI coding experience. |
| 50 | +- GitHub Copilot for Business: This paid tier is available for organizations with a GitHub Free or GitHub Team plan, or enterprises on GitHub Enterprise Cloud. GitHub Copilot Business gives organizations and enterprises control over Copilot policies, including which members can use Copilot. |
| 51 | +- GitHub Copilot Enterprise: This paid tier is available for enterprises on GitHub Enterprise Cloud. In addition to all of the Copilot Business features, Copilot Enterprise provides additional AI features on GitHub. With this subscription plan you can choose to assign either Copilot Enterprise or Copilot Business to each individual organization in the enterprise. |
| 52 | + |
| 53 | +Use the following steps to complete this section of the exercise: |
| 54 | + |
| 55 | +1. Open Visual Studio Code. |
| 56 | + |
| 57 | +1. On the left side menu, select **Extensions**. |
| 58 | + |
| 59 | +1. In the Search Extensions in Marketplace text box, type **GitHub Copilot** and then press Enter. |
| 60 | + |
| 61 | +1. In the filtered list of extensions, select the GitHub Copilot extension authored by GitHub. |
| 62 | + |
| 63 | +1. On the GitHub Copilot extension page, select **Install**. |
| 64 | + |
| 65 | +1. Watch for a GitHub authorization prompt. |
| 66 | + |
| 67 | + Your experience with authorization might vary depending on whether you've previously authorized Visual Studio Code for your GitHub account. |
| 68 | + |
| 69 | + - If you've authorized Visual Studio Code for your account on GitHub, GitHub Copilot is automatically authorized. |
| 70 | + |
| 71 | + - If you haven't authorized Visual Studio Code in your GitHub account, Visual Studio Code prompts you to sign in to GitHub. |
| 72 | + |
| 73 | + - If you don't receive a prompt asking you to authorize, select the bell icon on the far right side of Visual Studio Code's bottom panel. |
| 74 | + |
| 75 | + GitHub requests the necessary permissions for GitHub Copilot when the browser opens. |
| 76 | + |
| 77 | +1. To approve the authorization request, select **Authorize Visual Studio Code**. |
| 78 | + |
| 79 | + A dialog box named Visual Studio Code opens in Visual Studio Code. |
| 80 | + |
| 81 | +1. To confirm your GitHub authorization in the Visual Studio Code dialog box, select **Open**. |
| 82 | + |
| 83 | +## Configure GitHub Copilot extensions for Visual Studio Code |
| 84 | + |
| 85 | +GitHub Copilot settings are configured in your GitHub.com account and the Visual Studio Code environment. In Visual Studio Code, you access settings for GitHub Copilot and GitHub Copilot Chat using the GitHub Copilot status menu. The settings allow you to enable or disable GitHub Copilot for specific languages, configure the behavior of GitHub Copilot Chat, and customize the GitHub Copilot experience to suit your preferences. You can also configure GitHub Copilot settings on GitHub.com to manage your GitHub Copilot subscription, configure the retention of prompts and suggestions, and allow or block suggestions matching public code. |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | +### Enable or disable GitHub Copilot |
| 90 | + |
| 91 | +GitHub Copilot is enabled by default when you install the extension in Visual Studio Code. You can disable GitHub Copilot for a period of time if you need to. |
| 92 | + |
| 93 | +To view the enable and disable options for the GitHub Copilot extension, follow these steps: |
| 94 | + |
| 95 | +1. In Visual Studio Code, open the **Extensions** view. |
| 96 | + |
| 97 | +1. In the list of installed extensions, scroll down until you find **GitHub Copilot**. |
| 98 | + |
| 99 | +1. To display a dropdown menu for the GitHub Copilot extension that lists Enable and Disable options, select on the gear icon next to GitHub Copilot. |
| 100 | + |
| 101 | +  |
| 102 | + |
| 103 | +If you want to test the enable/disable options, you can select the disable option. However, be sure to re-enable GitHub Copilot before you continue with this exercise. |
| 104 | + |
| 105 | +## Configure GitHub Copilot and Copilot Chat in Visual Studio Code |
| 106 | + |
| 107 | +The GitHub Copilot extensions are configured with default settings when you install the extensions in Visual Studio Code. You can customize these settings to suit your preferences. |
| 108 | + |
| 109 | +Visual Studio Code provides two ways to access the settings for the GitHub Copilot extensions: |
| 110 | + |
| 111 | +- You can use the `Manage` icon to open the Visual Studio Code Settings tab. On the Settings tab, you can select **Extensions** and then select **Copilot**. |
| 112 | +- You can use the GitHub Copilot status icon to access the GitHub Copilot status menu and then select **Edit Settings**. |
| 113 | + |
| 114 | +Using the GitHub Copilot status menu to access settings opens the Visual Studio Code Settings tab with settings filtered for GitHub Copilot. Using the status menu is the quickest way to access the settings for the GitHub Copilot extensions. |
| 115 | + |
| 116 | +### Configure GitHub Copilot settings |
| 117 | + |
| 118 | +To view the configuration settings for GitHub Copilot, follow these steps: |
| 119 | + |
| 120 | +1. On Visual Studio Code's top menu bar, open the **Toggle Chat** dropdown menu. |
| 121 | + |
| 122 | + The Toggle Chat menu/button is located on the menu bar at the top of the Visual Studio Code window, just to the right of the Searchbox. It displays a small GitHub Copilot logo. |
| 123 | + |
| 124 | +  |
| 125 | + |
| 126 | +1. In the GitHub Copilot status menu, select **Configure Code Completions**, and then select **Edit Settings**. |
| 127 | + |
| 128 | +  |
| 129 | + |
| 130 | +1. Take a minute to review the list of available settings. |
| 131 | + |
| 132 | +  |
| 133 | + |
| 134 | + Notice that the settings for both GitHub Copilot and GitHub Copilot Chat are listed. Also, under the Extensions label on the left, both extensions are labeled as Copilot. The first Copilot extension is for GitHub Copilot and the second is for GitHub Copilot Chat. |
| 135 | + |
| 136 | +1. Under the Extensions label, select the first Copilot extension. |
| 137 | + |
| 138 | +  |
| 139 | + |
| 140 | + Notice that the settings list is now filtered for GitHub Copilot only. |
| 141 | + |
| 142 | + The settings for GitHub Copilot include the following options: |
| 143 | + |
| 144 | + - Enable Auto Completions |
| 145 | + - Enable or disable Copilot completions for specified languages |
| 146 | + |
| 147 | +1. Take a minute to review the settings for **Enable or disable Copilot completions for specified languages**. |
| 148 | + |
| 149 | + Notice that the settings for this option are configured using a list of languages and a value of **true** or **false** to enable or disable GitHub Copilot for each language. By default, GitHub Copilot is enabled for all languages. This setting is specified with the wildcard character `*` on the first row and the value **true**. The subsequent rows specify languages for which GitHub Copilot is enabled or disabled. For example, GitHub Copilot is enabled for **C#**, **JavaScript**, and **Python** and disabled for **Plaintext** and **Markdown**. |
| 150 | + |
| 151 | +1. Under **Enable or disable Copilot completions for specified languages**, select **markdown**. |
| 152 | + |
| 153 | + Notice that the value for Markdown is set to **false**. This means that GitHub Copilot is disabled for Markdown files. |
| 154 | + |
| 155 | +1. To enable Copilot for Markdown files, select **Edit Item** (pencil icon), select **false**, change the value to **true**, and then select **OK**. |
| 156 | + |
| 157 | +  |
| 158 | + |
| 159 | + You can now use GitHub Copilot document projects using Markdown files. |
| 160 | + |
| 161 | +1. Under the Extensions label, select the second Copilot extension. |
| 162 | + |
| 163 | +  |
| 164 | + |
| 165 | + Notice that the settings list is now filtered for GitHub Copilot Chat only. |
| 166 | + |
| 167 | + The settings for GitHub Copilot Chat include **Preview** and **Experimental** options. Setting choices include the following options: |
| 168 | + |
| 169 | + - **Fix Test Failure**: This option is enabled by default so that GitHub Copilot can provide suggestions for fixing test failures. |
| 170 | + - **Follow Ups**: By default, this setting is set to **firstOnly**, which means that GitHub Copilot provides follow-up suggestions only after the first suggestion. The other options are **always** and **never**. |
| 171 | + - **Local Override**: By default, this option is set to **auto**, which means that GitHub Copilot uses the locale of the Visual Studio Code display language. |
| 172 | + - **Scope Selection**: This option is disabled by default. When enabled, the user is prompted for a scope symbol when the user uses `/explain` in Chat without anything selected in the Editor. |
| 173 | + - **Terminal Chat Location**: The default setting is chatView, which specifies the Chat View. The other options are for the Quick Chat area and the Terminal. |
| 174 | + - **Use Project Templates**: This option is enabled by default so that GitHub Copilot uses relevant GitHub project templates when the user uses `/new` in Chat. |
| 175 | + - **Enable Code Actions**: This option is enabled by default so that GitHub Copilot can provide code actions in the Editor. |
| 176 | + - **Trigger Automatically**: This option is enabled by default so that GitHub Copilot suggestions are shown automatically as you type. |
| 177 | + |
| 178 | + We recommend keeping the default settings during this training. This helps to ensure that you have the expected experience when working on the modules in this learning path. When you have completed the training, you can experiment with these settings to customize your experience with GitHub Copilot and Copilot Chat. |
| 179 | + |
| 180 | + |
| 181 | + |
| 182 | +## Clean up |
| 183 | + |
| 184 | +<!-- Good practice - especially as self-paced learners will be using their own subscriptions --> |
| 185 | +<!-- Delete this section if it is not needed --> |
| 186 | + |
| 187 | +Now that you've finished the exercise, you should delete the cloud resources you've created to avoid unnecessary resource usage. |
| 188 | + |
| 189 | +1. Step 1 |
| 190 | +2. etc. |
0 commit comments