Skip to content

Commit 4fb1071

Browse files
mairawThraka
andauthored
add info about adding the package (#17150)
* 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>
1 parent 8d41f95 commit 4fb1071

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

docs/standard/analyzers/api-analyzer.md

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: .NET API analyzer
33
description: Learn how the .NET API Analyzer can help detect deprecated APIs and platform compatibility issues.
44
author: oliag
5-
ms.date: 04/26/2019
5+
ms.date: 02/20/2020
66
ms.technology: dotnet-standard
77
---
88
# .NET API analyzer
@@ -18,7 +18,7 @@ API Analyzer comes as a NuGet package [Microsoft.DotNet.Analyzers.Compatibility]
1818

1919
- Visual Studio 2017 and later versions, or Visual Studio for Mac (all versions).
2020

21-
## Discovering deprecated APIs
21+
## Discover deprecated APIs
2222

2323
### What are deprecated APIs?
2424

@@ -30,7 +30,21 @@ The .NET family is a set of large products that are constantly upgraded to bette
3030

3131
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.
3232

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
3448

3549
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:
3650

@@ -44,15 +58,15 @@ By clicking on the ID, you go to a webpage with detailed information about why t
4458

4559
Any warnings can be suppressed by right-clicking on the highlighted member and selecting **Suppress \<diagnostic ID>**. There are two ways to suppress warnings:
4660

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
4963

50-
### Suppressing warnings locally
64+
### Suppress warnings locally
5165

5266
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:
5367
!["Screenshot of code framed with #pragma warning disable"](media/api-analyzer/suppress-in-source.jpg)
5468

55-
### Suppressing warnings globally
69+
### Suppress warnings globally
5670

5771
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**.
5872

@@ -64,7 +78,7 @@ A *GlobalSuppressions.cs* file is added to your project after the first suppress
6478

6579
Global suppression is the recommended way to ensure consistency of API usage across projects.
6680

67-
## Discovering cross-platform issues
81+
## Discover cross-platform issues
6882

6983
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`.
7084

0 commit comments

Comments
 (0)