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
* add info about adding the package
* fix anchors
* Apply suggestions from code review
Co-Authored-By: Andy De George <2672110+Thraka@users.noreply.github.com>
Co-authored-by: Andy De George <2672110+Thraka@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/standard/analyzers/api-analyzer.md
+22-8Lines changed: 22 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: .NET API analyzer
3
3
description: Learn how the .NET API Analyzer can help detect deprecated APIs and platform compatibility issues.
4
4
author: oliag
5
-
ms.date: 04/26/2019
5
+
ms.date: 02/20/2020
6
6
ms.technology: dotnet-standard
7
7
---
8
8
# .NET API analyzer
@@ -18,7 +18,7 @@ API Analyzer comes as a NuGet package [Microsoft.DotNet.Analyzers.Compatibility]
18
18
19
19
- Visual Studio 2017 and later versions, or Visual Studio for Mac (all versions).
20
20
21
-
## Discovering deprecated APIs
21
+
## Discover deprecated APIs
22
22
23
23
### What are deprecated APIs?
24
24
@@ -30,7 +30,21 @@ The .NET family is a set of large products that are constantly upgraded to bette
30
30
31
31
The API Analyzer uses API-specific error codes that begin with DE (which stands for Deprecation Error), which allows control over the display of individual warnings. The deprecated APIs identified by the analyzer are defined in the [dotnet/platform-compat](https://github.com/dotnet/platform-compat) repo.
32
32
33
-
### Using the API Analyzer
33
+
### Add the API Analyzer to your project
34
+
35
+
1. Open Visual Studio.
36
+
2. Open the project you want to run the analyzer on.
37
+
3. In **Solution Explorer**, right-click on your project and choose **Manage NuGet Packages**. (This option is also available from the **Project** menu.)
38
+
4. On the NuGet Package Manager tab:
39
+
1. Select "nuget.org" as the Package source.
40
+
2. Go to the **Browse** tab.
41
+
3. Select **Include prerelease**.
42
+
4. Search for **Microsoft.DotNet.Analyzers.Compatibility**.
43
+
5. Select that package in the list.
44
+
6. Select the **Install** button.
45
+
7. Select the **OK** button on the **Preview Changes** dialog and then select the **I Accept** button on the **License Acceptance** dialog if you agree with the license terms for the packages listed.
46
+
47
+
### Use the API Analyzer
34
48
35
49
When a deprecated API, such as <xref:System.Net.WebClient>, is used in a code, API Analyzer highlights it with a green squiggly line. When you hover over the API call, a light bulb is displayed with information about the API deprecation, as in the following example:
36
50
@@ -44,15 +58,15 @@ By clicking on the ID, you go to a webpage with detailed information about why t
44
58
45
59
Any warnings can be suppressed by right-clicking on the highlighted member and selecting **Suppress \<diagnostic ID>**. There are two ways to suppress warnings:
46
60
47
-
-[locally (in source)](#suppressing-warnings-locally)
48
-
-[globally (in a suppression file)](#suppressing-warnings-globally) - recommended
61
+
-[locally (in source)](#suppress-warnings-locally)
62
+
-[globally (in a suppression file)](#suppress-warnings-globally) - recommended
49
63
50
-
### Suppressing warnings locally
64
+
### Suppress warnings locally
51
65
52
66
To suppress warnings locally, right-click on the member you want to suppress warnings for and then select **Quick Actions and Refactorings** > **Suppress *diagnostic ID*\<diagnostic ID>** > **in Source**. The [#pragma](../../csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning.md) warning preprocessor directive is added to your source code in the scope defined:
53
67

54
68
55
-
### Suppressing warnings globally
69
+
### Suppress warnings globally
56
70
57
71
To suppress warnings globally, right-click on the member you want to suppress warnings for and then select **Quick Actions and Refactorings** > **Suppress *diagnostic ID*\<diagnostic ID>** > **in Suppression File**.
58
72
@@ -64,7 +78,7 @@ A *GlobalSuppressions.cs* file is added to your project after the first suppress
64
78
65
79
Global suppression is the recommended way to ensure consistency of API usage across projects.
66
80
67
-
## Discovering cross-platform issues
81
+
## Discover cross-platform issues
68
82
69
83
Similar to deprecated APIs, the analyzer identifies all APIs that are not cross-platform. For example, <xref:System.Console.WindowWidth?displayProperty=nameWithType> works on Windows but not on Linux and macOS. The diagnostic ID is shown in the **Error List** window. You can suppress that warning by right-clicking and selecting **Quick Actions and Refactorings**. Unlike deprecation cases where you have two options (either keep using the deprecated member and suppress warnings or not use it at all), here if you're developing your code only for certain platforms, you can suppress all warnings for all other platforms you don't plan to run your code on. To do so, you just need to edit your project file and add the `PlatformCompatIgnore` property that lists all platforms to be ignored. The accepted values are: `Linux`, `macOS`, and `Windows`.
0 commit comments