Share via


Checking compatibility with .NET Portability Analyzer

With multiple project types now available in Visual Studio, it can sometimes get confusing which flavours of .NET work with which frameworks. This can now be compounded with .NET Core. Thus, creating code that is reusable means you need to take all factors into consideration so you can get maximum portability. Luckily, there is a tool that can help you port your .NET projects.

The Microsoft .NET Portability Analyzer is a free Visual Studio Add-in that offers a detailed report on the flexibility of your code. The report gives you an idea of how much work you need to do to make your application, library or project workable on other platforms, including .NET Core.

In this article, we will see how to install, set up and run the tool so we can see the detailed report it generates.

Installation

To install the .NET Portability Analyzer via Visual Studio, follow the steps below:

  1. Start Visual Studio 2015.
  2. Select Tools > Extensions and Updates.
  3. Select Online > Visual Studio Gallery.
  4. Search for the .NET Portability Analyzer using the Search box.
  5. Find the extension and click Download.
  6. Click Install to accept the terms.
  7. Click Restart Now to restart Visual Studio and complete the installation.

You can also download the package from the Visual Studio Marketplace. Install the extension package (ApiPort.vsix) by double-clicking it. This adds the Analyzer to Visual Studio and its various options to the context menus.

Finally, if you want to test your code outside Visual Studio, you can always run it from the command line using the console app. It can be downloaded and run from the GitHub repository.

Settings

Return Visual Studio and navigate to Tools > Options. A new page is added labelled .NET Portability Analyzer.

Viewing the General tab, we can see how many project types Microsoft can now target. The Analyzer has options for Excel, .NET Framework 4.6.2, and .NET Standard 1.6 checked by default.

Select the Target Platforms and their versions for the platforms you want to check portability for. Click OK to save your selections.

Note that the .NET platform targets and report formats are retrieved from Azure and thus are updated constantly.

Running The Analyzer

To run the .NET Portability Analyzer, open a project to inspect. Select the Analyze Assembly Portability option from the Analyze menu. Note you can also adjust the Analyzer settings by using the Portability Analyzer Settings menu item.

An open file dialog appears. From here you can select your project executable or .dll file. The Analyzer runs and compiles a .NET Portability Report for the selected file. It is displayed in the Portability Analysis Results dialog. Click the Open Report link to see the full analysis.

The report opens in Microsoft Excel. The first tab shows a Portability Summary for the selected target platforms. Under each one it displays a percentage of how portable the application is for the chosen platform. For a default MVC Web Application project in Visual Studio, we can see it’s 79% compatible with .NET Core / ASP.NET Core but only 69% with the new .NET Standard library.

The Details tab maps the assemblies in the current project to see if they are supported on the target platforms. There is also a recommended changes column. The Missing assemblies tab charts which assemblies need to be added to a conversion project.

You can also run the Analyzer from the Solution Explorer. Right-click either your solution or project and select Analyze Assembly Portability. The Portability Summary dialog still appears but now you also see warnings in the Error List. Clicking an error shows the incompatible line of code.

Summary

This article has shown you how easy it is to use the Microsoft .NET Portability Analyzer when porting your project, solution, or binaries to other platforms. The tool can help you plan out your project conversions by listing any issues and recommending solutions.

References