Leveraging existing code across .NET platforms

Today we are happy to announce the alpha release of the .NET Portability Analyzer extension for Visual Studio. Please try it out. This add-in was created by our software developer intern Charles Lowell.

Over the last few years, consumers and enterprise employees are using more devices than before which run different operating systems like iOS, Android, Windows Phone, and Windows 8. As a result developing apps for different platforms is almost a requirement now. With the release of the .NET Portability Analyzer extension we are integrating the ability to reason about portability of your existing code into your development environment. This will allow you an easy way to understand how portable your code is and get recommendations to write your code so that your code just works across platforms.

You may have seen Tech Ed 2014 announcements & .NET blog post on “Targeting Multiple Platforms”. This post continues from there.

Understanding portability with Visual Studio

In our previous post we introduced the command line .NET Portability Analyzer. However, we felt that the acquisition and discovery of the tool for developers would be aided if we were to integrate the experience into VS. Additionally the integration into Visual Studio allows us to pinpoint the source locations where incompatible APIs are found to be. You can download it here. There is a great Channel 9 video about the extension which you can watch below.

Once you have installed the extension you can use the Portability Analyzer in two ways

Analyze Assembly approach

This menu allows you to specify a set of libraries that you want to analyze and get a summary view of all the changes that would need to be made to make it compatible with a given platform.

The output of this analysis is a file that documents the overall compatibility of each assembly analyzed along with a detailed drill down into individual Types/Members that are missing and recommendations about how to fix them.

Analyze Project approach

The project analysis adds a context menu to the project dialog, where you can request to analyze a given project for portability. The image below illustrates this experience.

When using this experience in addition to the report shown above, you will also get source level information about compatibility issue where available, which will be reported as a message in the error list of VS as shown below.

Using the API Portability Analyzer extension will enable you to get a quick overview of all the changes that you would need to make in order to be able to port your code to a given platform. Given the assembly level break-down it enables you to easily prioritize and cost either the easiest ports or the most high value ports depending on your business requirements. We are actively working on the recommendations to make them actionable and informative.

Using the API Portability Analyzer

In case you don`t have VS or wanted to integrate this functionality into your build the API Portability Analyzer tool takes your existing app or library and provides a report which tells you how compatible you are with different platforms. Let’s take a quick look into how you could use the API Portability Analyzer. Download the tool from the site above and run the command as follows:

This command will analyze the Autfac libraries and give you a report Excel file, which summarizes the compatibility of the existing Autofac binaries against the different platform profiles.

We see that the assembly for Autofac is fully compatible with Silverlight and there are some missing dependencies for the Autofac.Configuration dll. If we wanted to drill into this further you can look at the details page in the excel sheet and see a view as follows.

The details page gives us information about the specific members that are missing from a type and recommendations around alternatives that can be used. We are actively working to fill out the recommendations for the missing APIs so that you have guidance around how you can move your code over to a given platform. You can use your inner Excel ninja to get different organizations around the work that needs to be done in order to move to a given platform. Remember pivot-tables are your friend.

Helping make the .NET framework better.

The API Portability Analyzer submits anonymous data to Microsoft about the .NET APIs used by your app. This aggregate data provides input to us on popular and missing APIs along with understanding where our customers are currently trying to migrate code from. As we work on our next set of features and compatibility reviews, this would help us spend more time on enabling APIs that you love and use most frequently. For instance based on the data, we are now working on enabling TypeConverter and System.Web types on the ASP.NET vNext K stack. The information that we collect is the .NET APIs that your app is using, along with some other metadata like what framework version your assembly was built against and assembly references of your assembly.
The dotnetstatus site gives you a visual sense of the data that we are collecting and we are looking at ways to add more value to this site. Your feedback around what features or data you would like to see here would be appreciated.

Wrapping Up

Using this tool enables you to quickly get a high level understanding of the work that needs to be done to port to a given platform. While it may appear that you would need to do work every time that you want to target a new platform, we on the .NET framework team are working to enable a vision of single .NET surface area. Our goal is to have parity across the APIs that we expose on our Modern framework stacks. The only reason for a missing API would be its lack of applicability to a given application model or platform.
The introduction of the Visual Studio extension makes it easy to reason about the migrating of code to a new platform. Depending on what your business requirements are you can easily prioritize and understand the costs of supporting a new platform. In addition this tool give us insights into the biggest pain points that you face when migrating your code. We would love to hear your feedback on how to make this tool better! Please let us know what you think by either leaving a comment on this post or reaching out to the team at NETAPIPort@Microsoft.com.