7.6 KiB
title, shortTitle, product, intro, versions, topics
| title | shortTitle | product | intro | versions | topics | |||
|---|---|---|---|---|---|---|---|---|
| Getting started with GitHub Copilot in Visual Studio | Visual Studio | {% data reusables.gated-features.copilot %} | Learn how to install {% data variables.product.prodname_copilot %} in {% data variables.product.prodname_vs %}, and start seeing suggestions as you write comments and code. |
|
|
About {% data variables.product.prodname_copilot %} and Visual Studio
{% data reusables.copilot.procedural-intro %}
If you use {% data variables.product.prodname_vs %}, you can view and incorporate suggestions from {% data variables.product.prodname_copilot %} directly within the editor. This guide demonstrates how to use {% data variables.product.prodname_copilot %} within {% data variables.product.prodname_vs %} for Windows.
Prerequisites
To use {% data variables.product.prodname_copilot %} in {% data variables.product.prodname_vs %}, you must have {% data variables.product.prodname_vs %} 2022 17.1 or later installed. For more information, see the Visual Studio IDE documentation.
{% note %}
Note: {% data variables.product.prodname_copilot %} is not currently available for use with Visual Studio for Mac.
{% endnote %}
Installing the {% data variables.product.prodname_vs %} extension
To use {% data variables.product.prodname_copilot %}, you must first install the {% data variables.product.prodname_vs %} extension.
- In the Visual Studio toolbar, under Extensions, click Manage Extensions.

- In the "Manage Extensions" dialogue, click Visual Studio Marketplace, search for the {% data variables.product.prodname_copilot %} extension and click Download.

- Close the "Manage Extensions" dialog, then exit and relaunch {% data variables.product.prodname_vs %}.
- Optionally, to check that {% data variables.product.prodname_copilot %} is installed and enabled, go back to Manage Extensions, click Installed to view your currently installed extensions and click {% data variables.product.prodname_copilot %} to see status information.

Authorizing {% data variables.product.prodname_copilot %}
- Create a new C# Console App project. For more information, see steps 1 and 2 in "Tutorial: Create a simple C# console app in Visual Studio" in the Microsoft Visual Studio documentation.
- Name your project "Copilot Demo" and click Next.

- Click Create to create the project.

- To copy your device activation code, in the dialog box about authorizing {% data variables.product.prodname_copilot %}, click OK.

- A device code will be copied automatically to the clipboard. Paste it on the {% data variables.product.company_short %} device authorization page that will open. If you miss the device code, you will find it in the status bar, at the bottom left of {% data variables.product.prodname_vs %}, as well as on the {% data variables.product.prodname_copilot %} output window pane.
- After successful authorization, proceed to read and approve the {% data variables.product.prodname_copilot %} Telemetry Terms.

After installation, a {% data variables.product.prodname_copilot %} icon will appear within the margin for the editor, in the lower-left corner of your {% data variables.product.prodname_vs %} window.
Seeing your first suggestion
{% data reusables.copilot.supported-languages %} The following samples are in C#, but other languages will work similarly.
{% data reusables.copilot.create-c-file %}
- In the C# file, type the following function header. {% data variables.product.prodname_copilot %} will automatically suggest an entire function body in grayed text, as shown below. The exact suggestion may vary.
function calculateDaysBetweenDates(begin, end) {
{% data reusables.copilot.accept-suggestion %}
Seeing alternative suggestions
{% data reusables.copilot.alternative-suggestions %} {% data reusables.copilot.create-c-file %}
- In the C# file, type the following function header. {% data variables.product.prodname_copilot %} will show you a suggestion.
function calculateDaysBetweenDates(begin, end) {
- To see alternative suggestions, press Alt+] (or Alt+[).
- Optionally, you can hover over the suggestion to see the {% data variables.product.prodname_copilot %} command palette for choosing suggestions. {% data reusables.copilot.accept-or-reject-suggestion %}
Generating code suggestions from comments
{% data reusables.copilot.generating-suggestions-from-comments %}
{% data reusables.copilot.create-c-file %}
- In the C# file, type the following comment. {% data variables.product.prodname_copilot %} will suggest an implementation of the function.
using System.Xml.Linq; var doc = XDocument.Load("index.xhml"); // find all images
{% data reusables.copilot.accept-suggestion %}
Enabling and disabling {% data variables.product.prodname_copilot %}
The {% data variables.product.prodname_copilot %} status icon in the bottom panel of the {% data variables.product.prodname_vs %} window indicates whether {% data variables.product.prodname_copilot %} is enabled or disabled. When enabled, the background color of the icon will match the color of the status bar. When disabled, it will have a diagonal line through it.
-
To enable or disable {% data variables.product.prodname_copilot %}, click the {% data variables.product.prodname_copilot %} icon in the bottom panel of the {% data variables.product.prodname_vs %} window.

-
If you are disabling {% data variables.product.prodname_copilot %}, you will be asked whether you want to disable suggestions globally, or for the language of the file you are currently editing.
- To disable suggestions from {% data variables.product.prodname_copilot %} globally, click Enable Globally.
- To disable suggestions from {% data variables.product.prodname_copilot %} for the specified language, click Enable for LANGUAGE.