Tuesday, July 10, 2012

GoTo Portable Class Libraries - Now's the time to start using them as your default Class Project template?

//InterKnowlogy/ Blogs - Make Portable Libraries Your Go-To Project Template

"With the upcoming release of Visual Studio 2012, Portable Libraries will finally be built into the product. The 2012 iteration of Portable Libraries is much improved from the prior versions, adding not only new platforms (Windows 8 Metro) but greatly increasing the list of available framework library classes that can be used across the various platforms.

For those not familiar with Portable Libraries, they are a variant of the standard Class Library VS project type which allows targeting multiple platform versions of the .NET CLR with a single project that compiles to a single common DLL. In 2012 the available platforms are:

  • Full .NET Framework 4.0+
  • Silverlight 4, 5
  • Windows Phone 7+
  • Windows 8 Metro
  • Xbox (very limited)


Even if you have no immediate need for multiple platforms, starting out with a Portable Library instead of a standard Class Library can help extend the life of your code and save a lot of work in the future. Imagine being able to create a fully functional Metro version of your application a year or two down the road by just layering a new (also XAML) UI design on top of the code originally written for the WPF or Silverlight, without needing to modify a single line of that underlying code to make it compatible..."

You've all heard about the Portable Class Library Project type right? Write once, use just about everywhere in the .Net world? No?

Portable Class Library

"The Portable Class Library project in Visual Studio 2012 RC enables you to write and build managed assemblies that work on multiple .NET Framework platforms. For example, you can create classes that contain shared business logic for desktop apps, Windows Metro style apps, and mobile apps, and you can then reference those classes from those projects.

Using a Portable Class Library project, you can build portable assemblies that work without modification in .NET Framework, Metro style, Silverlight, Windows Phone, and Xbox 360 apps. The Portable Class Library project supports a subset of assemblies from these platforms, and provides a Visual Studio template that you can use to build assemblies that run without modification on these platforms. If you don't use a Portable Class Library project, you must target a single app type and then manually rework the class library for other app types.

The features of the Portable Class Library are described in the following sections:

  • Prerequisites
  • Target Platforms
  • Assemblies
  • Finding the Supported Members in Reference Documentation
  • Supporting the Model-View-View Model (MVVM) Pattern
  • Creating a Portable Class Library Project
  • Selecting the Platforms to Target
  • Using the Portable Class Library


If you're creating a Class Library project, why not start with a Portable by default and then only change it if/when you need a feature that isn't supported? It shouldn't cost you much in time and could save you much in the future. I mean imaging taking that business or utility library and just auto-magically being able to reuse it?

BTW, you can also use it with .Net 4.0 and VS2010 too, Portable Class Libraries (vs.100)


Related Past Post XRef:
Update 4.0.3 for Microsoft .NET Framework 4 Roundup
Write (.Net library) once, use everywhere (in .Net world)? The Portable Library Tools CTP Released. (Think “Reusing/Sharing the same Project between SilverLight, XNA, Windows Phone, etc” or “DRY .Net Project Style” )

No comments: