You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code-quality/code-metrics-values.md
+4-1Lines changed: 4 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Calculate code metrics in Visual Studio
3
-
ms.date: 12/12/2017
3
+
ms.date: 11/02/2018
4
4
ms.prod: visual-studio-dev15
5
5
ms.technology: vs-ide-code-analysis
6
6
ms.topic: "conceptual"
@@ -34,6 +34,9 @@ The following list shows the code metrics results that Visual Studio calculates:
34
34
35
35
-**Lines of Code** - Indicates the approximate number of lines in the code. The count is based on the IL code and is therefore not the exact number of lines in the source code file. A very high count might indicate that a type or method is trying to do too much work and should be split up. It might also indicate that the type or method might be hard to maintain.
36
36
37
+
> [!NOTE]
38
+
> The [command-line version](../code-quality/how-to-generate-code-metrics-data.md#command-line-code-metrics) of the code metrics tool counts actual lines of code because it analyzes the source code instead of IL.
39
+
37
40
## Anonymous methods
38
41
39
42
An *anonymous method* is just a method that has no name. Anonymous methods are most frequently used to pass a code block as a delegate parameter. Metrics results for an anonymous method that is declared in a member, such as a method or accessor, are associated with the member that declares the method. They are not associated with the member that calls the method.
title: How to generate code metrics data in Visual Studio
3
-
ms.date: 12/12/2017
2
+
title: Generate code metrics from the IDE or command line
3
+
ms.date: 11/02/2018
4
4
ms.prod: visual-studio-dev15
5
5
ms.technology: vs-ide-code-analysis
6
6
ms.topic: "conceptual"
@@ -16,33 +16,149 @@ ms.workload:
16
16
---
17
17
# How to: Generate code metrics data
18
18
19
-
You can generate code metrics results for an entire solution or the selected project.
19
+
You can generate code metrics results for one or more projects or an entire solution. Code metrics is available within the Visual Studio interactive development environment (IDE) and, for C# and Visual Basic projects, at the command line.
20
20
21
-
## To generate code metrics results for an entire solution
21
+
In addition, you can install a [NuGet package](https://dotnet.myget.org/feed/roslyn-analyzers/package/nuget/Microsoft.CodeAnalysis.FxCopAnalyzers/2.6.2-beta2-63202-01) that includes four code metrics [analyzer](roslyn-analyzers-overview.md) rules: CA1501, CA1502, CA1505, and CA1506. These rules are disabled by default, but you can enable them from **Solution Explorer** or in a [rule set](using-rule-sets-to-group-code-analysis-rules.md) file.
22
22
23
-
- From the menu bar, choose **Analyze** > **Calculate Code Metrics** > **For Solution**.
23
+
## Visual Studio IDE code metrics
24
24
25
-
\- or -
25
+
### Generate code metrics results for an entire solution
26
26
27
-
- In **Solution Explorer**, right-click the solution and then choose **Calculate Code Metrics**.
27
+
You can generate code metrics results for an entire solution in any of the following ways:
28
+
29
+
- From the menu bar, choose **Analyze** > **Calculate Code Metrics** > **For Solution**.
28
30
29
-
\- or -
31
+
- In **Solution Explorer**, right-click the solution and then choose **Calculate Code Metrics**.
30
32
31
33
- In the **Code Metrics Results** window, choose the **Calculate Code Metrics for Solution** button.
32
34
33
-
The results are generated and the **Code Metrics Results** window is displayed.
35
+
The results are generated and the **Code Metrics Results** window is displayed. To view the results details, expand the tree in the **Hierarchy** column.
34
36
35
-
##To generate code metrics results for one or more selected projects
37
+
### Generate code metrics results for one or more projects
36
38
37
39
1. In **Solution Explorer**, select one or more projects.
38
40
39
-
1. From the menu bar, choose **Analyze** > **Calculate Code Metrics** > **For <project\>**.
40
-
41
-
The results are generated and the **Code Metrics Results** window is displayed.
42
-
43
-
## To view the results details
44
-
45
-
In the **Code Metrics Results** window, expand the tree in the **Hierarchy** column.
41
+
1. From the menu bar, choose **Analyze** > **Calculate Code Metrics** > **For Selected Project(s)**.
42
+
43
+
The results are generated and the **Code Metrics Results** window is displayed. To view the results details, expand the tree in the **Hierarchy**.
44
+
45
+
## Command-line code metrics
46
+
47
+
You can generate code metrics data from the command line for C# and Visual Basic projects for .NET Framework, .NET Core, and .NET Standard apps. The command line code metrics tools is called *Metrics.exe*.
48
+
49
+
To obtain the *Metrics.exe* executable, you must [generate it yourself](#generate-the-executable). In the near future, a [published version of *Metrics.exe* will be available](https://github.com/dotnet/roslyn-analyzers/issues/1756) so you don't have to build it yourself.
50
+
51
+
### Generate the executable
52
+
53
+
To generate the executable *Metrics.exe*, follow these steps:
54
+
55
+
1. Clone the [dotnet/roslyn-analyzers](https://github.com/dotnet/roslyn-analyzers) repo.
56
+
2. Open Developer Command Prompt for Visual Studio as an administrator.
57
+
3. From the root of the **roslyn-analyzers** repo, execute the following command: `Restore.cmd`
58
+
4. Change directory to *src\Tools*.
59
+
5. Execute the following command to build the **Metrics.csproj** project:
Previous versions of Visual Studio, including Visual Studio 2015, included a command-line code metrics tool called *Metrics.exe*. This previous version of the tool did a binary analysis, that is, an assembly-based analysis. The new tool analyzes source code instead. Because the new *Metrics.exe* is source code-based, the results are different to what's generated by previous versions of *Metrics.exe* and within the Visual Studio 2017 IDE.
144
+
145
+
The new *Metrics.exe* tool can compute metrics even in the presence of source code errors, as long as the solution and project can be loaded.
146
+
147
+
#### Metric value differences
148
+
149
+
The `LinesOfCode` metric is more accurate and reliable in the new *Metrics.exe*. It is independent of any codegen differences and doesn’t change when the toolset or runtime changes. The new *Metrics.exe* counts actual lines of code, including blank lines and comments.
150
+
151
+
Other metrics such as `CyclomaticComplexity` and `MaintainabilityIndex` use the same formulas as previous versions of *Metrics.exe*, but the new *Metrics.exe* counts the number of `IOperations` (logical source instructions) instead of intermediate language (IL) instructions. The numbers will be slightly different from previous versions of *Metrics.exe* and from the Visual Studio 2017 IDE code metrics results.
152
+
153
+
### Legacy mode
154
+
155
+
You can also choose to build *Metrics.exe* in *legacy mode*. The legacy mode version of the tool generates metric values that are closer to what older versions of the tool generated. Additionally, in legacy mode, *Metrics.exe* generates code metrics for the same set of method types that previous versions of the tool generated code metrics for. For example, it doesn't generate code metrics data for field and property initializers. Legacy mode is useful for backwards compatibility or if you have code check-in gates based on code metrics numbers. The command to build *Metrics.exe* in legacy mode is:
Copy file name to clipboardExpand all lines: docs/code-quality/working-with-code-metrics-data.md
+18-37Lines changed: 18 additions & 37 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,9 @@
1
1
---
2
-
title: The Code Metrics Results window in Visual Studio
2
+
title: Code Metrics window
3
3
ms.date: 12/12/2017
4
4
ms.prod: visual-studio-dev15
5
5
ms.technology: vs-ide-code-analysis
6
-
ms.topic: "conceptual"
6
+
ms.topic: reference
7
7
f1_keywords:
8
8
- "vs.codemetrics.output"
9
9
helpviewer_keywords:
@@ -16,33 +16,31 @@ manager: douge
16
16
ms.workload:
17
17
- "multiple"
18
18
---
19
-
# Using the Code Metrics Results window
19
+
# Use the Code Metrics Results window
20
20
21
21
The **Code Metrics Results** window displays the data that is generated by the code metrics analysis. For more information about code metrics data values, see [Code metrics values](../code-quality/code-metrics-values.md).
22
22
23
-
## Displaying code metrics results
23
+
## Display code metrics results
24
24
25
25
The **Code Metrics Results** window is displayed automatically when you generate code metrics results. You can also display the window at any time.
26
26
27
-
### To display the Code Metrics Results window
27
+
You can display the Code Metrics Results window using one of the following menu sequences:
28
28
29
29
- On the **Analyze** menu, choose **Windows** > **Code Metrics Results**.
30
30
31
-
\- or -
32
-
33
31
- On the **View** menu, choose **Other Windows** > **Code Metrics Results**.
34
32
35
-
The **Code Metrics Results** window is displayed, even if it contains no results.
33
+
The **Code Metrics Results** window opens, even if it contains no results.
36
34
37
35
### To view code metrics details
38
36
39
37
If code metrics results have been generated, expand the tree in the **Hierarchy** column.
40
38
41
-
## Filtering code metrics results
39
+
## Filter code metrics results
42
40
43
41
You can filter the results that are displayed in the **Code Metrics Results** window by using the toolbar at the top. For example, you might want to see only the results that have a maintainability index below 65.
44
42
45
-
The **Filter** drop-down box contains the names of the results columns. When a filter is defined, it is added to the bottom of the list together with an indentation. The list can contain the last ten filters that were defined.
43
+
The **Filter** drop-down box contains the names of the results columns. When a filter is defined, it is added to the bottom of the list together with an indentation. The list can contain the last 10 filters that were defined.
46
44
47
45
### To filter the code metrics results
48
46
@@ -56,46 +54,29 @@ The **Filter** drop-down box contains the names of the results columns. When a f
56
54
57
55
5. To see the result details, expand the hierarchy tree.
58
56
59
-
## Adding, removing, and rearranging data columns
60
-
61
-
You can add or remove results columns from the **Code Metrics Results** window . In addition, you can rearrange results columns so that they appear in the order that you want.
57
+
## Add, remove, and rearrange data columns
62
58
63
-
### To remove a column
59
+
You can add or remove results columns from the **Code Metrics Results** window. In addition, you can rearrange results columns so that they appear in the order that you want.
64
60
65
-
1. Click the **Add/Remove Columns** button.
61
+
### Add or remove a column
66
62
67
-
\- or -
68
-
Right-click any column heading and then click **Add/Remove Columns**.
63
+
1. Click the **Add/Remove Columns** button, or right-click any column heading and then click **Add/Remove Columns**.
69
64
70
-
1. In the **Add/Remove Columns** dialog box, clear the check box for the column that you want to remove and then click**OK**.
65
+
1. In the **Add/Remove Columns** dialog box, select or clear the check box for the column that you want to add or remove, and then choose**OK**.
71
66
72
-
### To add a previously removed column
67
+
### Rearrange columns
73
68
74
69
1. Click the **Add/Remove Columns** button.
75
70
76
-
\- or -
77
-
78
-
Right-click any column heading and then click **Add/Remove Columns**.
79
-
80
-
1. In the **Add/Remove Columns** dialog box, select the check box for the column that you want to add and then click **OK**.
81
-
82
-
### To rearrange columns
83
-
84
-
1. Click the **Add/Remove Columns** button.
85
-
86
-
\- or -
87
-
88
-
Right-click any column heading and then click **Add/Remove Columns**.
89
-
90
-
1. In the **Add/Remove Columns** dialog box, select the column that you want to move and then click either the up arrow or the down arrow.
71
+
1. In the **Add/Remove Columns** dialog box, select the column that you want to move and then choose either the up arrow or the down arrow.
91
72
92
-
1. When the column is positioned where you want it, click**OK**.
73
+
1. When the column is positioned where you want it, choose**OK**.
93
74
94
-
## Copying data to the clipboard or Excel
75
+
## Copy data to the clipboard or Excel
95
76
96
77
You can select and copy a selected row of code metrics data to the clipboard as a text string that contains one line for the name and value of each data column. You can also click **Open Selection in Microsoft Excel** to export all of the code metrics results to an Excel spreadsheet.
97
78
98
-
## Creating a work item based on code metric results
79
+
## Create a work item based on code metric results
99
80
100
81
You can create an [Azure Boards](/azure/devops/boards/index?view=vsts) work item that is based on results in the **Code Metric Results** window. When the work item is created, Visual Studio automatically enters a title in the **Title** field and code metrics data under the **History** tab.
0 commit comments