Skip to content

Commit 4828e81

Browse files
authored
legacy projects (#48804)
1 parent 3e029ce commit 4828e81

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

docs/core/project-sdk/msbuild-props.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: MSBuild properties for Microsoft.NET.Sdk
33
description: Reference for the MSBuild properties and items that are understood by the .NET SDK.
4-
ms.date: 11/07/2024
4+
ms.date: 09/30/2025
55
ms.topic: reference
66
ms.custom: updateeachrelease
77
---
@@ -994,7 +994,7 @@ The following table shows the values you can specify.
994994
>
995995
> - If you set [EnforceCodeStyleInBuild](#enforcecodestyleinbuild) to `true`, this property affects [code-style (IDEXXXX) rules](../../fundamentals/code-analysis/style-rules/index.md) (in addition to code-quality rules).
996996
> - If you set a compound value for `AnalysisLevel`, you don't need to specify an [AnalysisMode](#analysismode). However, if you do, `AnalysisLevel` takes precedence over `AnalysisMode`.
997-
> - This property has no effect on code analysis in projects that don't reference a [project SDK](overview.md), for example, legacy .NET Framework projects that reference the Microsoft.CodeAnalysis.NetAnalyzers NuGet package.
997+
> - This property has no effect on code analysis in projects that don't reference a [project SDK](overview.md), for example, legacy .NET Framework projects that reference the Microsoft.CodeAnalysis.NetAnalyzers NuGet package. For more information, see [Enable code analysis in legacy projects](../../fundamentals/code-analysis/overview.md#enable-code-analysis-in-legacy-projects).
998998
999999
### AnalysisLevel\<Category>
10001000

@@ -1047,7 +1047,6 @@ The following table shows the available option values. They're listed in increas
10471047
>
10481048
> - If you set [EnforceCodeStyleInBuild](#enforcecodestyleinbuild) to `true`, this property affects [code-style (IDEXXXX) rules](../../fundamentals/code-analysis/style-rules/index.md) (in addition to code-quality rules).
10491049
> - If you use a compound value for [AnalysisLevel](#analysislevel), for example, `<AnalysisLevel>9-recommended</AnalysisLevel>`, you can omit this property entirely. However, if you specify both properties, `AnalysisLevel` takes precedence over `AnalysisMode`.
1050-
> - This property has no effect on code analysis in projects that don't reference a [project SDK](overview.md), for example, legacy .NET Framework projects that reference the Microsoft.CodeAnalysis.NetAnalyzers NuGet package.
10511050
10521051
### AnalysisMode\<Category>
10531052

docs/fundamentals/code-analysis/overview.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Code analysis in .NET
33
titleSuffix: ""
44
description: Learn about source code analysis in the .NET SDK.
5-
ms.date: 11/10/2024
5+
ms.date: 09/30/2025
66
ms.topic: overview
77
ms.custom: updateeachrelease
88
helpviewer_keywords:
@@ -11,12 +11,7 @@ helpviewer_keywords:
1111
---
1212
# Overview of .NET source code analysis
1313

14-
.NET compiler platform (Roslyn) analyzers inspect your C# or Visual Basic code for code quality and style issues. Starting in .NET 5, these analyzers are included with the .NET SDK and you don't need to install them separately. If your project targets .NET 5 or later, code analysis is enabled by default. If your project targets a different .NET implementation, for example, .NET Core, .NET Standard, or .NET Framework, you must manually enable code analysis by setting the [EnableNETAnalyzers](../../core/project-sdk/msbuild-props.md#enablenetanalyzers) property to `true`.
15-
16-
If you don't want to move to the .NET 5+ SDK, have a non-SDK-style .NET Framework project, or prefer a NuGet package-based model, the analyzers are also available in the [Microsoft.CodeAnalysis.NetAnalyzers NuGet package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers). You might prefer a package-based model for on-demand version updates.
17-
18-
> [!NOTE]
19-
> .NET analyzers are target-framework agnostic. That is, your project does not need to target a specific .NET implementation. The analyzers work for projects that target .NET 5+ as well as earlier .NET versions, such as .NET Core 3.1 and .NET Framework 4.7.2. However, to enable code analysis using the [EnableNETAnalyzers](../../core/project-sdk/msbuild-props.md#enablenetanalyzers) property, your project must reference a [project SDK](../../core/project-sdk/overview.md).
14+
.NET compiler platform (Roslyn) analyzers inspect your C# or Visual Basic code for code quality and style issues. These analyzers are included with the .NET SDK and you don't need to install them separately. If your project targets .NET 5 or later, code analysis is enabled by default. (For information about enabling code analysis in projects that target .NET Framework, see [Enable code analysis in legacy projects](#enable-code-analysis-in-legacy-projects).)
2015

2116
If rule violations are found by an analyzer, they're reported as a suggestion, warning, or error, depending on how each rule is [configured](configuration-options.md). Code analysis violations appear with the prefix "CA" or "IDE" to differentiate them from compiler errors.
2217

@@ -231,6 +226,20 @@ dotnet_diagnostic.CA1822.severity = none
231226
232227
For more information and other ways to suppress warnings, see [How to suppress code analysis warnings](suppress-warnings.md).
233228
229+
## Enable code analysis in legacy projects
230+
231+
If your project targets .NET 5 or later, code analysis is enabled by default. If your project targets .NET Standard or .NET Framework, you must manually enable code analysis by setting the [EnableNETAnalyzers](../../core/project-sdk/msbuild-props.md#enablenetanalyzers) property to `true`.
232+
233+
If your project uses the legacy project file format, that is, it doesn't reference a [project SDK](../../core/project-sdk/overview.md), there are some additional steps you must take to enable code analysis:
234+
235+
1. Add a reference to the [📦 Microsoft.CodeAnalysis.NetAnalyzers NuGet package](https://www.nuget.org/packages/Microsoft.CodeAnalysis.NetAnalyzers).
236+
1. Instead of setting [`AnalysisLevel`](../../core/project-sdk/msbuild-props.md#analysislevel), which isn't understood by non-SDK-style projects, add the following properties to your project file:
237+
238+
```xml
239+
<EffectiveAnalysisLevel>9</EffectiveAnalysisLevel>
240+
<AnalysisMode>Recommended</AnalysisMode>
241+
```
242+
234243
## Third-party analyzers
235244

236245
In addition to the official .NET analyzers, you can also install third party analyzers, such as [StyleCop](https://www.nuget.org/packages/StyleCop.Analyzers/), [Roslynator](https://www.nuget.org/packages/Roslynator.Analyzers/), [XUnit Analyzers](https://www.nuget.org/packages/xunit.analyzers/), and [Sonar Analyzer](https://www.nuget.org/packages/SonarAnalyzer.CSharp/).

0 commit comments

Comments
 (0)