Microsoft has implemented multiple generic Roslyn static code analysis rules both for C# and Visual Basic. These rules allow you to produce safe, reliable and maintainable code by helping you find and correct bugs, vulnerabilities and code smells in your codebase. It is strongly advised to enable these rules on all your projects.
For .NET 5 and later,
See: learn.microsoft.com/dotnet/fundamentals/code-analysis/overview
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
</PropertyGroup>
</Project>