Scott Hanselman

Getting ready for the future with the Microsoft .NET Portability Analyzer

December 3, '14 Comments [10] Posted in Learning .NET
Sponsored By

.NET has been getting more and more portable. Not only is .NET Open Source going forward (read Announcing .NET 2015 - .NET as Open Source, .NET on Mac and Linux, and Visual Studio Community) but you of course know about Xamarin tools, as well as, I hope, the .NET Microframework, and much more.

You can run your .NET code all over, and there's a tool to make this even easier. While you'll rarely get 100% portable code with any platform, you can get into the magic 90-95% with smart refactoring, then keep the platform-specific shims pluggable.

The .NET Portability Analyzer is a free Visual Studio Add-in (or console app) that will give you a detailed report on how portable your code is. Then you can get a real sense of how far you can take your code, as well as how prepared you'll be for the Core CLR and alternate platforms.

.NET Portability

Take a look at this report on AutoFac, for example. You can see that the main assembly is in fantastic shape across most platforms. Understandably the more platform-specific Configuration assembly fares worse, but still there's a complete list of what methods are available on what platforms, and a clear way forward.

.NET Portability Report

You'll get suggestions with a direction to head when you bump up against a missing or not-recommended API.

img2

You can analyze specific assemblies, or an entire project. Once installed, you'll find the commands under the Analyze menu, and you can change options in the .NET Portability Analyzer options in the Tools | Options menu.

Even better, you can use this with the FREE Visual Studio Community that you can download at http://www.visualstudio.com/free.

Related Links

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Wednesday, 03 December 2014 20:10:59 UTC
This is very useful. I'm guessing it can be run with legacy applications so you can see what you need to do to make your shared class libraries multi platform.

But this and everything else that's happening is making it far easier to walk away from Windows - I really can't see a good business case for using Windows for greenfield projects. I find it hard to believe MS embracing OSS is down to altruism and I am genuinely confused by Microsoft's strategy. All welcome though :-)
Matthew Blott
Wednesday, 03 December 2014 20:45:54 UTC
@Matthew: It's not altruism, it's necessity. MSFT (not MS, ask both Bing and Google -- that is a disease!) played a major ace card in keeping themselves relevant for the foreseeable future by going OSS. Well, I should say it's MSFT + Xamarin = relevance, really. If you are saying there is confusion in developing for WinRT, then I 100% agree with you. MSFT completely missed the mark with that joke of a stack.

Fortunately, Xamarin.Forms already has a community port for WinRT (and WPF), so you can build your application with one codebase and hit around 2.5B devices and workstations. That is something that no other managed code technology can claim to do, anywhere. Building a Xamarin.Forms application is like building a JavaScript application, but with organized namespaces (read: things make sense), superior performance, and most importantly... XAML! :)
MichaelD!
Thursday, 04 December 2014 13:32:15 UTC
Interesting timing on this blog post, right after Rocky Lhotka's interview with .NET Rocks on Universal Apps where the take-away I got was that shared projects with #IFDEFs was the way to go for cross-platform projects, yielding a much cleaner codebase overall as opposed to a slim-functionality PCL with lots of adaptation/plumbing code per platform. With any luck the areas of .NET supported by the various platforms will increase to the point that PCLs will be a true write-once-run-anywhere answer to multi-platform, non-repetitive code reuse.
Mike C.
Thursday, 04 December 2014 13:51:25 UTC
Maybe it's just me, but I feel like the "platforms" being displayed in the report could use a little clarification. Telling me my code won't run on Windows 8.1, when I'm very obviously running the code on Windows 8.1, is a little misleading unless you're smart enough to realize it's probably referring to Windows 8.1 apps.. The same goes for the other platforms listed... it's not clear that, for example, ASP.NET vNext 1.0 probably (not sure) means the CoreCLR...
Thursday, 04 December 2014 17:29:21 UTC
Suggestion #37 in the last screenshot is ridiculous !
What portable is in Environment.GetEnvironmentVariable("COMPUTERNAME") ?
Ventsyslav Raikov
Wednesday, 10 December 2014 14:09:04 UTC
Really confusing!
Mike
Wednesday, 10 December 2014 22:56:05 UTC
don't worry Mike you've been doing it right, .Net core (asp.net--) is open source so your should sign up for xamarin. oh and someone made a tool in case you don't know where dev stack will deploy , just in case you don't know already.(easy peazzy lemon squizzy).
Tuesday, 16 December 2014 01:14:29 UTC
You do mention .net microframework, but in the screenshot i do not see it as an option. why is this?

I use netduino, netduino plus, and netduino plus 2 at this time.

also, other devices, such as various Arduino devices, with shields and associated MS Visual studio plug ins(i.e. Visual Micro). although these do not run on .net microframework does this plug in auto detect their presence?

Additionally, with the up and coming Internet of Things and how it may interact with the big data enterprise, what kind of add-in tools will MS come up with for realization of toolsets? IoT is going to be larger than the cellular industry, as it covers all industries. I hope that MS is prepared for this. Feedback?
Ron
Wednesday, 17 December 2014 21:42:35 UTC
the " Internet of Things" is a fabulous new buzzword I like way it sounds, I like the way big data sound too, new buzzwords are the best, they make you seem relevant and are a sure sign to everyone that your a future focus developer. I really feel good about the " I hope that MS is prepared for this,Feedback?" makes them wonder is this merely "Feedback" or the cleverly veiled threat from a truly historical genius, no one can say, oh my, the suspense is just spine chilling.
Friday, 23 January 2015 16:53:46 UTC
The .NET Portability Analyzer only supports VS 2013 and 2014. Is it possible I use with the previous version of Visual Studio? (e.g. 2012)
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.