Checking compatibility with .NET Portability Analyzer

This article is also available on the Microsoft TechNet Wiki.

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.

Port01

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.

Port02

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.

Port03

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.

Port04

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.

Port05

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.

Port06

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.

Port07

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.

Port08

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

Advertisements

About Ken Cenerelli
I am a Programmer Writer, .NET Developer, Microsoft MVP - Visual Studio and Development Technologies, Public Speaker, Blogger, and Microsoft Azure Nerd. I blog regularly at kencenerelli.wordpress.com and can be found on Twitter via @KenCenerelli.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: