Announcing Portable Library Tools CTP [Justin Van Patten]

Today we're announcing the CTP release of a new add-in for
Visual Studio 2010 that makes it easy to create C# and Visual Basic libraries
that run on a variety of .NET platforms without recompilation.

Download the Portable
Library Tools CTP
today (install VS 2010 SP1 Beta first).

Creating Portable Libraries

The Portable Library Tools CTP adds a new "Portable Class
Library" project template to Visual Studio that can be used to create class libraries
in C# and VB that run on the various .NET platforms without recompiling.

Portable Class Library projects and assemblies can be
referenced and used by .NET 4, Silverlight 4, Windows Phone 7, and XNA for Xbox
360 projects.

Target Platforms Determine Available APIs

Within a Portable Class Library project, you can specify
which .NET platforms the library is intended to run on.  Although there is a 'core' set APIs that are
available on all platforms, there are also some APIs that are only available on
certain platforms.  An example of an API
that exists on some platforms but not others is MEF.  Windows Phone and Xbox 360 do not currently
have built-in support for MEF, but .NET and Silverlight do.  If you want to use MEF within a portable
library, the library will currently only run on .NET and Silverlight.

Thus, the project's selected target platforms determine
which APIs can be used within the project. 
The APIs that are shown in intellisense and available to the compiler
are automatically filtered based on the selected target platforms, so you don't
need to have any special knowledge about each platform or worry about
inadvertently using an API that doesn't exist on a platform that you're
targeting.  The project system takes care
of this for you.

In the future, as the underlying platforms evolve to support
more APIs that could be portable, we'll update the API surface available to
portable libraries as appropriate.

The following table summarizes the high-level functionality currently
available on each platform:

Feature

.NET

Silverlight

Windows Phone

Xbox 360

Core BCL

Yes

Yes

Yes

Yes

Core XML

Yes

Yes

Yes

Yes

Core HTTP

Yes

Yes

Yes

-

WCF Client

Yes

Yes

Yes

-

MEF

Yes

Yes

-

-

 

Note: Once you've installed the Portable Library Tools CTP,
you can use the Object Browser in Visual Studio for a more in-depth look at the
individual APIs available for use within portable libraries.

You can write a surprising amount of portable code with the
subset of APIs currently available to portable libraries.  Everything from business logic to web service
client proxies can be portable.  This
enables you to implement most, if not all, application logic in portable
assemblies (and then use the portable assemblies in apps that have
form-factor-specific UIs for a given platform).

We're still in the process of defining the APIs that will be
available to portable libraries, so expect some minor tweaks and additions before
the final release of the tools.  We'd
love to get your feedback on what's currently available in the CTP.  Is there anything you think is missing that
should be available to portable libraries? 
How easy was it to make your existing libraries portable?

Known Limitations in the CTP

Deploying Portable Libraries

The CTP of the Portable Library Tools is not a "go live"
release.  There are still some rough
edges that need smoothing out before the final release.  One area that does not currently have a
complete experience is around deploying portable libraries.

Making portable libraries work on platforms such as .NET
Framework 4 and Silverlight 4 required making some minor changes to those
platforms.  In order for portable
libraries to work correctly on these platforms, you'll need to ensure the
necessary updates have been applied. 
Silverlight for Windows Phone 7 and XNA Framework 4.0 for Xbox 360 do
not require any updates to run portable assemblies.

.NET Framework 4
Update

An update to .NET Framework 4 is required to run portable
libraries.  For developers, this update
is automatically installed as part of Visual Studio SP1 Beta, so you shouldn't
need to install it on a machine that already has VS 2010 SP1 installed.  A standalone beta of this update is currently
available for download here.  The final release of the Portable Library
Tools will provide a way for developers to add a prerequisite to their
installer to ensure the update is applied on end-user machines when your app is
deployed.

Silverlight 4
Update

An update to Silverlight 4 is required to run portable
libraries.  This update hasn't been
released yet, but the impact in the meantime should be limited.  As long as you avoid using the following APIs
in your portable libraries, they will run just fine on Silverlight 4 without
the update:

  • System.Xml.XmlReader.Dispose
  • System.Xml.XmlWriter.Dispose
  • System.Net.WebResponse.Dispose

In the meantime, if you need to dispose these objects, you
can wrap them in a using statement or cast the object to IDisposable before
calling Dispose.

Once the Silverlight 4 update is available, we will provide
instructions on how to specify it as the minimum version required for your
application.

Visual Basic Support

The Add Service Reference is currently disabled for VB
projects.  This will be resolved in a
future update.

Summary

We're excited to make a CTP of the Portable
Library Tools
available for you to try out. 
Download the CTP today and let us know what you think!

Also, you may be interested in watching Shawn Burke's PDC
2010 session on 3-Screen
Coding: Sharing code between Windows Phone, Silverlight, and .NET
, which
provides some more background on portable libraries.