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.

Comments

  • Anonymous
    January 19, 2011
    It would be great to hook into Mono MOMA and include Mono as a target.

  • Anonymous
    January 19, 2011
    I second what Gareth said. Mono, MonoTouch/MonoDroid support would be great.

  • Anonymous
    January 19, 2011
    Exactly my thoughts on Mono. Miguel, are you reading this?

  • Anonymous
    January 19, 2011
    What about deploying one of those portable libraries to SQLCLR? As I understand the Core BCL and Core XML (of most of them) could be run from with SQLCLR. Or am I missing something?

  • Anonymous
    January 19, 2011
    Could this be open source? Should this be open source? Being able to help with issues, offer wrappers, and target other platforms (Micro CLR, Mono) would be great reasons.

  • Anonymous
    January 19, 2011
    So can we add a project reference to a "portable library" from both .NET and Silverlight apps? I know the binary compatibility is there as of .NET 4/SL4, but Visual Studio won't let you add a project reference -- you have to browse to the .dll and add a reference to that, and so it doesn't rebuild when it needs to. Will there be a way to use something better than the absolute lowest common denominator? It would be fantastic to be able to write ViewModel logic, INotifyPropertyChanged, etc. to share between a .NET app and a Silverlight app. I don't care about XNA or phone, so I don't want functionality taken away just because they don't support something.

  • Anonymous
    January 19, 2011
    This is one of the new project types that uses the VBCore functionality implemented in SP1 blogs.msdn.com/.../vb-core-new-compilation-mode-in-visual-studio-2010-sp1.aspx

  • Anonymous
    January 19, 2011
    The comment has been removed

  • Anonymous
    January 25, 2011
    Great news! I'm working on a project that compiles to all these platforms (including Mono) and managing all the .csproj has been a real pain.

  • Anonymous
    January 30, 2011
    The comment has been removed

  • Anonymous
    February 15, 2011
    The comment has been removed