Home > Mobile >  Analyze dotnet code for platform dependencies
Analyze dotnet code for platform dependencies

Time:04-17

Is there a code or assembly analyzer that will determine the platform dependencies of the code? For example, to note whether the code has a Windows dependency.

ApiPort.exe won't do it: it just indicates whether you are compatible with .Net (vs. .Net Framework). Your code can get all green on .Net 6 compatibility but still have a Windows dependency. (e.g., by using System.Security.AccessControl.FileSystemAclExtensions.)

A build will tell you, via the warning warning CA1416: This call site is reachable on all platforms. 'FileSystemSecurity.AddAccessRule(FileSystemAccessRule)' is only supported on: 'windows'. But to get that, you need to be building against a.Net 5/6 target, and my code isn't ready for that. Still I want to know, how much Windows dependency do I have?

Suggestions? Tools?

CodePudding user response:

Microsoft documented it very well in this article

The analyzer is enabled by default only for projects that target .NET 5 or later and have an AnalysisLevel of 5 or higher. You can enable it for target frameworks lower than net5.0 by adding the following key-value pair to an .editorconfig file in your project:

dotnet_code_quality.enable_platform_analyzer_on_pre_net5_target=true
  • Related