Skip to content

Commit dcbb018

Browse files
committed
add info about legacy mode
1 parent 353ce4b commit dcbb018

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

docs/code-quality/how-to-generate-code-metrics-data.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,21 @@ To generate the executable *Metrics.exe*, follow these steps:
5656
2. Open Developer Command Prompt for Visual Studio as an administrator.
5757
3. From the root of the **roslyn-analyzers** repo, execute the following command: `Restore.cmd`
5858
4. Change directory to *src\Tools*.
59-
5. Execute the following command to build the **Metrics.csproj** project: `msbuild /m /v:m /p:Configuration=Release Metrics.csproj`
59+
5. Execute the following command to build the **Metrics.csproj** project:
60+
61+
```shell
62+
msbuild /m /v:m /p:Configuration=Release Metrics.csproj
63+
```
6064

6165
An executable named *Metrics.exe* is generated in the *Binaries* directory under the repo root.
6266

67+
> [!TIP]
68+
> To build *Metrics.exe* in [legacy mode](#legacy-mode), execute the following command:
69+
>
70+
> ```shell
71+
> msbuild /m /v:m /t:rebuild /p:LEGACY_CODE_METRICS_MODE=true Metrics.csproj
72+
> ```
73+
6374
### Usage
6475
6576
To run *Metrics.exe*, supply a project or solution and an output XML file as arguments. For example:
@@ -139,6 +150,16 @@ The `LinesOfCode` metric is more accurate and reliable in the new *Metrics.exe*.
139150

140151
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.
141152

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:
156+
157+
```shell
158+
msbuild /m /v:m /t:rebuild /p:LEGACY_CODE_METRICS_MODE=true Metrics.csproj
159+
```
160+
161+
For more information, see [Enable generating code metrics in legacy mode](https://github.com/dotnet/roslyn-analyzers/pull/1841).
162+
142163
## See also
143164

144165
- [Use the Code Metrics Results window](../code-quality/working-with-code-metrics-data.md)

0 commit comments

Comments
 (0)