Sunday, August 12, 2012

Portable Library Tools & Supported Feature Set

In the previous post we discussed how we can use Portable Library tools to develop an application. The view model and model libraries were created as portable libraries targeting .Net Framework 4.5 and Silverlight 4 frameworks.

You might be wondering how to determine the features supported in a set of target framework combinations. I have noticed different profiles being maintained for different target framework combinations. These features would be based on the assemblies available in the .Net portable subset.

Basically the available feature set for target frameworks is resolved by maintaining different profiles for each possible combination. If you have Portable Library Tools installed on your machine then you should be able to find the various profiles just for this. I can see the following profiles:

Each of these profiles is about a certain selection of the frameworks. It seems that the selection of frameworks in the framework selection dialog creates the mapping suggesting the selection of a particular profile. The profile has the details of the supported frameworks. The following profile supports .Net for Metro style apps, .Net framework 4.0.3 and Silverlight 5 frameworks.

This is the definition of one of the xml files in the folder shown above.

The profile also has the details of the features supported by specifying the list of assemblies maintained in FrameworkList.xml.

The following profile is for the target frameworks including .NET for Metro style apps, .NET Framework 4, Silverlight 4, Windows Phone 7, Xbox 360). Just look at the minimum features supported as small overlapping area in these frameworks' feature set.

The list grows as we reduce the number of target frameworks. The following is the profile for the selection of frameworks including .NET Framework 4.0.3 and Silverlight 4.

The above libraries are themselves retargetable libraries. We also remember from our last discussions that portable libraries can only reference other portable libraries. We can use ILDASM to verify our claim. Here we are looking at the definition of System.dll for one of the profiles.

Please note that ILDASM is one of the Windows SDK tools. I can find it in the following folder on my machine.

C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools

Now let us discuss a bit how these reference assemblies are used during development. Basically, these are not the files which would be loaded during runtime. At that time, the runtime would load that version of the library which would be supported by host platform. The portable libraries can be loaded by any framework in the list of frameworks they are targeting. These reference libraries just contain metadata specifying where to look for definition of a particular type requested. This is generally a redirection to some other namespace possibly in a different assembly.

Allowing Only Certain Target Frameworks
As we have been discussing that we can target different frameworks including .net frameworks, Silverlight, Metro, Xbox360 and Windows Phone.

Can we exclude certain frameworks? e.g. what if we don't want our development machines to be creating libraries excluding Xbox360. Can we do that? The answer is yes we can.

In order to do that just search the profiles targeting Xbox 360 and remove them from the folder.

No comments: