Skip to content

Commit fe57df5

Browse files
Merge pull request #10194 from MicrosoftDocs/main638484880845009781sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 906e4bf + 3561c10 commit fe57df5

File tree

82 files changed

+685
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+685
-418
lines changed

docs/ide/finding-references.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Finding references in your code
33
description: Explore the Find All References command in Visual Studio to find references to particular code elements in your code, including by reference type.
4-
ms.date: 02/15/2023
4+
ms.date: 04/10/2024
55
ms.topic: conceptual
66
helpviewer_keywords:
77
- code editor, find all references
@@ -13,30 +13,29 @@ ms.subservice: general-ide
1313
---
1414
# Find references in your code
1515

16-
You can use the **Find All References** command to find where particular code elements are referenced throughout your codebase. The **Find All References** command is available on the context (right-click) menu of the element you want to find references to. Or, if you're a keyboard user, press **Shift + F12**.
16+
You can use the **Find All References** command to find where particular code elements are referenced throughout your codebase. The **Find All References** command is available on the context (right-click) menu of the element you want to find references to. Or, press **Alt + F2**.
1717

1818
The results appear in a tool window named **\<element> references**, where *element* is the name of the item you're searching for. A toolbar in the **references** window enables you to do the following:
1919

20-
- Change the scope of the search in a drop-down list box. You can choose to look only in changed documents all the way up to the entire solution.
21-
- Copy the selected referenced item by choosing the **Copy** button.
22-
- Choose buttons to go to the next or previous location in the list, or press the **F8** and **Shift + F8** keys to do so.
20+
- Change the scope of the search in a drop-down list box. You can choose to look only in open or changed documents, all the way up to the entire solution.
21+
- Copy the selected referenced item(s) by choosing the **Copy** button. All the values in all the columns for all selected rows are copied to the clipboard, preceded by the column headings. This makes it easy to paste into a spreadsheet.
22+
- Choose buttons to go to the next or previous location in the list, or press the up and down arrow keys to do so.
2323
- Remove any filters on the returned results by choosing the **Clear All Filters** button.
2424
- Change how returned items are grouped by choosing a setting in the **Group by:** drop-down list box.
2525
- Keep the current search results window by choosing the **Keep Results** button. When you choose this button, the current search results stay in this window, and new search results appear in a new tool window.
2626
- Search for strings within the search results by entering text in the **Search Find All References** text box.
2727

28-
You can also hover the mouse over any search result to see a preview of the reference.
28+
You can also hover the mouse over any search result to see the reference in the context of the surrounding code.
2929

3030
![Screenshot of the Find All References tool window.](../ide/media/vside_findallreferences.png)
3131

3232
## Navigate to references
3333

3434
You can use the following methods to navigate to references in the **references** window:
3535

36-
- Press **F8** to go to the next reference, or **Shift + F8** to go to the previous reference.
3736
- Press the **Enter** key on a reference, or double-click it, to go to it in code.
3837
- On the right-click menu (context menu) of a reference, choose the **Go To Previous Location** or **Go To Next Location** commands.
39-
- Choose the **Up Arrow** and **Down Arrow** keys (if they're enabled in the **Options** dialog box). To enable this functionality, on the menu bar, choose **Tools** > **Options** > **Environment** > **Tabs and Windows**, and then in the **Preview Tab** section, select the **Allow new files to be opened in the preview tab** and **Preview selected files in Find Results** boxes.
38+
- Use the **Up Arrow** and **Down Arrow** keys.
4039

4140
## Change reference groupings
4241

@@ -52,6 +51,10 @@ In C# or Visual Basic, the **Find References** window has a **Kind** column wher
5251

5352
After you apply a filter or a filter set, you can easily remove it by using the **Clear All Filters** button.
5453

54+
## Customize the experience
55+
56+
To customize the experience, on the menu bar, choose **Tools** > **Options** > **Environment** > **Tabs and Windows**, and then in the **Preview Tab** section, if you select the **Allow new files to be opened in the preview tab** checkbox, you can select or unselect the **Preview selected files in Find Results** checkbox. When selected, the file is opened in the editor at the place where the reference occurs. When unset, the file is only opened if you explicitly press **Enter** or double-click on the row.
57+
5558
## Related content
5659

5760
- [Navigating code](../ide/navigating-code.md)
Loading
3.5 KB
Loading
Loading
Lines changed: 110 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,123 @@
11
---
22
title: Insert XML documentation comments
3-
description: Learn how to insert XML documentation comments in your code that you can use to create a compiler-generated XML file to distribute alongside your .NET assembly.
4-
ms.date: 11/23/2021
5-
ms.topic: reference
3+
description: Learn how to insert XML documentation comments in your code and create a compiler-generated XML comments file to distribute with your .NET assembly.
4+
ms.date: 04/11/2024
5+
ms.topic: how-to
66
author: mikadumont
77
ms.author: midumont
88
manager: mijacobs
99
ms.subservice: general-ide
1010
---
1111
# Insert XML comments for documentation generation
1212

13-
Visual Studio can help you document code elements such as classes and methods, by automatically generating the standard XML documentation comment structure. At compile time, you can generate an XML file that contains the documentation comments. To enable that option, select **Generate a file containing API documentation** on the **Build** > **Output** tab of your project's properties.
13+
This article describes how Visual Studio can help you document code elements such as classes and methods by automatically generating the standard XML documentation comment structure. At compile time, you can generate an XML file that contains the documentation comments.
1414

15-
> [!TIP]
16-
> If you want to configure a non-default name and location for the documentation file, add the [DocumentationFile](/dotnet/core/project-sdk/msbuild-props#documentationfile) property to your *.csproj*, *.vbproj*, or *.fsproj* file.
17-
18-
The compiler-generated XML file can be distributed alongside your .NET assembly so that Visual Studio and other IDEs can use IntelliSense to show quick information about types and members. Additionally, the XML file can be run through tools like [DocFX](https://dotnet.github.io/docfx/) and [Sandcastle](https://www.microsoft.com/download/details.aspx?id=10526) to generate API reference websites.
15+
You can distribute the compiler-generated XML file along with your .NET assembly so that Visual Studio and other IDEs can use IntelliSense to show quick information about types and members. You can also run the XML file through tools like [DocFX](https://dotnet.github.io/docfx/) and [Sandcastle](https://www.microsoft.com/download/details.aspx?id=10526) to generate API reference websites.
1916

2017
> [!NOTE]
21-
> The **Insert Comment** command that automatically inserts XML documentation comments is available in [C#](/dotnet/csharp/programming-guide/xmldoc/) and [Visual Basic](/dotnet/visual-basic/programming-guide/program-structure/how-to-create-xml-documentation). However, you can manually insert [XML documentation comments in C++](/cpp/build/reference/xml-documentation-visual-cpp) files and still generate XML documentation files at compile time.
22-
23-
## To insert XML comments for a code element
24-
25-
1. Place your text cursor above the element you want to document, for example, a method.
26-
27-
2. Do one of the following:
28-
29-
- Type `///` in C#, or `'''` in Visual Basic
30-
31-
- From the **Edit** menu, choose **IntelliSense** > **Insert Comment**
32-
33-
- From the right-click or context menu on or just above the code element, choose **Snippet** > **Insert Comment**
34-
35-
The XML template is immediately generated above the code element. For example, when commenting a method, it generates the **\<summary\>** element, a **\<param\>** element for each parameter, and a **\<returns\>** element to document the return value.
36-
37-
![XML comment template - C#](media/doc-preview-cs.png)
38-
39-
![XML comment template - Visual Basic](media/doc-preview-vb.png)
40-
41-
3. Enter descriptions for each XML element to fully document the code element.
42-
43-
![Screenshot showing the completed comment.](media/doc-result-cs.png)
44-
45-
You can use styles in XML comments that will render in Quick Info when hovering over the element. These styles include: italics, bold, bullets, and a clickable link.
46-
47-
![Screenshot showing the completed comment with style tags for italics, bold, bullets, and a clickable link.](media/doc-style-cs.png)
48-
49-
> [!NOTE]
50-
> There is an [option](../../ide/reference/options-text-editor-csharp-advanced.md) to toggle XML documentation comments after typing `///` in C# or `'''` Visual Basic. From the menu bar, choose **Tools** > **Options** to open the **Options** dialog box. Then, navigate to **Text Editor** > **C#** (or **Visual Basic**) > **Advanced**. In the **Editor Help** section, look for the **Generate XML documentation comments** option.
51-
52-
## See also
18+
> The **Insert Comment** command to automatically insert XML documentation comment structure is available in [C#](/dotnet/csharp/programming-guide/xmldoc/) and [Visual Basic](/dotnet/visual-basic/programming-guide/program-structure/how-to-create-xml-documentation). For C++, you can [manually insert XML documentation comments](/cpp/build/reference/xml-documentation-visual-cpp) and still generate XML documentation files at compile time.
5319
54-
- [Documenting your code with XML comments (C# Guide)](/dotnet/csharp/language-reference/xmldoc/)
55-
- [How to: Create XML documentation (Visual Basic)](/dotnet/visual-basic/programming-guide/program-structure/how-to-create-xml-documentation)
56-
- [C++ Comments](/cpp/cpp/comments-cpp)
57-
- [XML Documentation (C++)](/cpp/build/reference/xml-documentation-visual-cpp)
58-
- [Code generation](../code-generation-in-visual-studio.md)
20+
## Enable documentation generation
21+
22+
::: moniker range=">= vs-2022"
23+
To enable documentation generation, select the **Generate a file containing API documentation** checkbox on the **Build** > **Output** tab of your project's properties.
24+
25+
By default, a documentation file named the same as your assembly with an *.xml* file extension generates in the same directory as the assembly. If you want to configure a nondefault name or location for the file, enter or browse to an alternate location under **XML documentation file path**.
26+
::: moniker-end
27+
28+
::: moniker range="<= vs-2019"
29+
To enable documentation generation, select the **XML documentation file** checkbox in the **Build** > **Output** section of your project's properties.
30+
31+
By default, a documentation file named the same as your assembly with an *.xml* file extension generates in the same directory as the assembly. If you want to configure a nondefault name or location for the file, enter or browse to an alternate location.
32+
::: moniker-end
33+
34+
Alternatively, you can add the [GenerateDocumentationFile](/dotnet/core/project-sdk/msbuild-props#generatedocumentationfile) or [DocumentationFile](/dotnet/core/project-sdk/msbuild-props#documentationfile) properties to your *.csproj*, *.vbproj*, or *.fsproj* file. Set `GenerateDocumentationFile` to `true` to generate a documentation file with the default name and location. Use the `DocumentationFile` property to specify a different name or location.
35+
36+
If you use `DocumentationFile` by itself or with the `GenerateDocumentationFile` property set to `true`, a documentation file with the specified name and location is generated. However, if you set `GenerateDocumentationFile` to `false`, no documentation file is generated even if you set the `DocumentationFile` property.
37+
38+
## Enable comment insertion keyboard shortcut
39+
40+
You can set the [Comments](options-text-editor-csharp-advanced.md#comments) option to automatically insert XML comment structures after you type `///` in C# or `'''` in Visual Basic.
41+
42+
1. From the Visual Studio menu bar, choose **Tools** > **Options**.
43+
1. In the **Options** dialog box, navigate to **Text Editor** > **C#** (or **Visual Basic**) > **Advanced**.
44+
1. Under the **Comments** section, select or deselect **Generate XML documentation comments for \\\\\\** (or **'''**).
45+
46+
## Automatically insert an XML comment
47+
48+
1. In Visual Studio, place your cursor above the element you want to document, for example a method.
49+
50+
1. Take one of the following actions:
51+
52+
- If the automatic comment insertion shortcut is enabled, type `///` in C#, or `'''` in Visual Basic.
53+
- From the **Edit** menu, choose **IntelliSense** > **Insert Comment**.
54+
- From the right-click or context menu, choose **Snippet** > **Insert Comment**.
55+
56+
The XML comment structure is immediately generated above the code element. For example, when commenting the following `GetUserName` method, the template generates the `<summary>` element, a `<param>` element for the parameter, and a `<returns>` element to document the return value.
57+
58+
```csharp
59+
/// <summary>
60+
///
61+
/// </summary>
62+
/// <param name="id"></param>
63+
/// <returns></returns>
64+
public string GetUserName(int id)
65+
{
66+
return "username";
67+
}
68+
```
69+
70+
```vb
71+
''' <summary>
72+
'''
73+
''' </summary>
74+
''' <param name="id"></param>
75+
''' <returns></returns>
76+
Public Function GetUserName(id As Integer) As String
77+
Return "username"
78+
End Function
79+
```
80+
81+
1. Enter descriptions for each XML element to fully document the code. For example:
82+
83+
```csharp
84+
/// <summary>
85+
/// Gets the username associated with the specified ID.
86+
/// </summary>
87+
/// <param name="id">The unique user ID.</param>
88+
/// <returns>A string containing the username for the specified ID.</returns>
89+
public string GetUserName(int id)
90+
{
91+
return "username";
92+
}
93+
```
94+
You can use XML elements and styles in comments that render in Quick Info when you hover over the code. These elements include italic or bold styles, bulleted or numbered lists, and clickable `cref` or `href` links.
95+
96+
For example, enter the following code into a C# program file:
97+
98+
```csharp
99+
/// <summary>
100+
/// There are two <see href="https://bing.com">params</see>.
101+
/// <list type="number">
102+
/// <item><param name="id">The user <em>id</em></param></item>
103+
/// <item><param name="username">The user <em>name</em></param></item>
104+
/// </list>
105+
/// </summary>
106+
/// <returns>The <strong>username</strong>.</returns>
107+
public static string GetUserName(int id)
108+
{
109+
return "username";
110+
}
111+
```
112+
113+
When you hover over **GetUserName**, the Quick Info pane appears as follows:
114+
115+
![Screenshot showing the completed comment with style tags for a clickable link, a numbered list, and italic and bold formatting.](media/doc-style-cs.png)
116+
117+
## Related content
118+
119+
- [Documentation comments](/dotnet/csharp/language-reference/xmldoc/)
120+
- [XML documentation in Visual Basic](/dotnet/visual-basic/programming-guide/program-structure/how-to-create-xml-documentation)
121+
- [Comments (C++)](/cpp/cpp/comments-cpp)
122+
- [XML Documentation (Visual C++)](/cpp/build/reference/xml-documentation-visual-cpp)
123+
- [Code generation](../writing-code-in-the-code-and-text-editor.md#generate-fix-or-refactor-code)
28.8 KB
Loading

0 commit comments

Comments
 (0)