API Analyzers, introduced with ASP.NET Core 2.2, enable you to follow a set of conventions to improve the documentation of the APIs of your ASP.NET Core applications. API Analyzers work with any controller that is decorated with the [ApiController] attribute. This article discusses how we can work with API Analyzers in ASP.NET Core 3.1.
To work with the code examples provided in this article, you should have Visual Studio 2019 installed in your system. If you don’t already have a copy, you can download Visual Studio 2019 here.
First off, let’s create an ASP.NET Core project in Visual Studio. Assuming Visual Studio 2019 is installed in your system, follow the steps outlined below to create a new ASP.NET Core project in Visual Studio.
This will create a new ASP.NET Core API project in Visual Studio. Now select the Controllers solution folder in the Solution Explorer window and click “Add -> Controller…” to create a new controller named DefaultController. We’ll use this project in the subsequent sections of this article.
If you are using with ASP.NET Core 2.2, to work with API Analyzers in ASP.NET Core, you should install the Microsoft.AspNetCore.Mvc.Api.Analyzers package from NuGet. You can do this either via the NuGet Package Manager inside the Visual Studio 2019 IDE, or by executing the following command in the NuGet Package Manager Console:
Install-Package Microsoft.AspNetCore.Mvc.Api.Analyzers
Note that you do not need to install the NuGet package if you are using ASP.NET Core 3.0 or higher because the analyzers are included as part of the .NET Core 3.x SDK.
#api #asp.net #microsoft #.net #software development