The .NET Portability Analyzer is a powerful tool designed to help developers evaluate the portability of their .NET code across various .NET implementations, including .NET Core, .NET Standard, and UWP. This article provides an in-depth guide on how to use the .NET Portability Analyzer to ensure your libraries and applications are compatible with multiple platforms.
The .NET Portability Analyzer is a console application that analyzes assemblies and provides a detailed report on .NET APIs that are missing for the applications or libraries to be portable on the specified targeted .NET platforms. The tool is available on GitHub and can be used to identify potential issues and make informed decisions about porting your code.
When it comes to porting your .NET code, there are several common targets to consider:
To use the .NET Portability Analyzer, follow these steps:
ApiPort.exe
command, specifying the directory or file to analyze.-t
parameter to target a specific version of .NET.To analyze portability, run the following command:
ApiPort.exe analyze -f .
This will analyze the current directory and provide a detailed report on the portability of your code.
The portability report will show the portability percentage for each assembly included in the run. The report will also list the APIs missing from any of the selected targeted platforms, including:
If you find a Missing Assemblies section in your report, it means that there are assemblies referenced by your analyzed assemblies that were not analyzed. Include these assemblies in the API portability analyzer run to get a detailed, API-level portability report.
For more information on the .NET Portability Analyzer, visit the GitHub documentation. You can also collaborate with the community on GitHub and create and review issues and pull requests.
The .NET Portability Analyzer is a powerful tool that helps developers ensure their .NET code is compatible with multiple platforms. By following the steps outlined in this article, you can use the .NET Portability Analyzer to identify potential issues and make informed decisions about porting your code. Remember to always include all related .exe and .dll files and exclude files that your app depends on but you don't own and can't port. With the .NET Portability Analyzer, you can ensure your libraries and applications are future-proof and compatible with the latest .NET implementations.