C# CONCEPTS

Automatically Identify Bugs in Your Code With .NET 5

Sukhpinder Singh | C# .Net
The Startup

--

.Net SDK now incorporates rich diagnostics and code recommendations in the .NET SDK by default.

In the past, it’s unwilling to add new warnings to C#. Its because adding recent warnings is technically a source breaking change for users who have notifications set as errors.

C# compiler uses Analysis Level to introduce warnings for these patterns in a safe way.

Analysis Level is bound to the target framework of your project except you manually change what your project targets. SDK allows you to set your analysis level, though visual studio manually.

Example of Analysis Level 5

<Project Sdk="Microsoft.NET.Sdk"><PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AnalysisLevel>5</AnalysisLevel>
</PropertyGroup>
</Project>

If you always choose to be on the highest supported analysis level by default, then specify “latest” in your project file:

<AnalysisLevel>latest</AnalysisLevel>

If you are comfortable with “preview” .Net versions

<AnalysisLevel>preview</AnalysisLevel>

--

--

Sukhpinder Singh | C# .Net
The Startup

.Net Developer - Editor at .Net Programming with ~48K views per month, Looking for C# writers. Link: https://medium.com/c-sharp-programming