Migrating to Mango – Developer View. Part 3

Part 1 of this article is available here.

Part 2 of this article is available here.

What’s the difference between WP7.0 and WP7.1 projects?

As already mentioned the project properties offer the target selection. However, the things are not that simple. Old projects can be upgraded to WP7.1, but once you do that, Visual Studio does not let you downgrade the project back to WP7.0. (The corresponding option gets lost.) On the other hand, it is not difficult to bypass this limitation. Here is how you can downgrade WindowsPhone71 project to 7.0:

  • In the *.csproj file:

TargetFrameworkProfile: Substitute “WindowsPhone71” for “WindowsPhone

  • In the WMAppManifest.xml:

AppPlatformVersion: Substitute “7.1” -> “7.0

Remove capabilities ID_CAP_ISV_CAMERA, ID_CAP_CONTACTS, ID_CAP_APPOINTMENTS

  • In the project references:

Remove reference to mscorlib.extensions. (This dll contains f.e. definition of INotifyPropertyChanging.)

How to create an installer for a Control Library

The problem:

We have controls library developed for old WP7, i.e. it does not refer to Mango-specific fuctionality. Can we offer this library for Mango phones?  If so, do we have to recompile it with new Mango SDK? Which target to select? (7.0 or 7.1) Do we need to offer two binaries – one for each target?

Of course, the ideal solution would be to use a single binary. Let’s look for it. Google and stackoverflow.com did not yield any help, I was left on my own. As usual I started with experiments. I created 2 versions of Resco.Controls.dll – one targeting WP7.0 and the other one for WP7.1. I tried to use these dlls in differently targeted projects.

Note that there are several ways how to use a control library in your application project:

1. Installed library is offered if it matches the project type

In case of WP7.0 the installation means that the folder where the library dll file resides is written in the Registry key

HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Silverlight for Phone\v4.0\AssemblyFoldersEx

Libraries installed this way are offered in Add References dialog .NET tab providing that their target (profile) matches the project target. I.e. WP7.0 libraries for WP7.0 projects and WP7.1 libraries for WP7.1 projects.

2. By browsing you can add downwards compatible library

If you use Add References dialog Browse tab, you can select any library dll file. This way you can add a reference to a compatible library (as above), but also a reference from a WP7.1 project to a WP7.0 library. However, you can’t refer WP7.1 library from a WP7.0 project. (You get the error “A reference to a higher version or incompatible assembly cannot be added to the project.“)

3. By hacking the xap file you can add any library

Xap file is the final product of your project that serves as the application installer. It is a zip file and as such you can browse its content.  Do it, it is rather instructive. You will find here both your application dll, but also the library dll. Surprisingly, you can modify the Xap file by placing there another version of the control library. This bypasses any compatibility checks as you can this way install WP7.0 application using WP7.1 library. I did this on a WP7.0 device, maybe new devices (or Marketplace) will use stronger security checks to prevent this action.

Content of the xap file

Final solution – improving dll registration

Interesting results, but they did not answer the original question.I decided for the last trial – to install the Mango release of the WP7 Toolkit and analyze the Registry changes.

WP7.1 libraries appear to be registered at

HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Silverlight for WindowsPhone\v4.0\AssemblyFoldersEx

Knowing above, I created new library installer that used WP7.0 library and registered it in both Registry folders mentioned above. This was it – single binary serving all kinds of projects. (I.e. the library can be added from Add References dialog .NET tab for both WP7.0 and WP7.1 projects.)

Registration info for Resco.Controls assembly

To be continued…

About the author

Jan Slodicka
Programming for over 30 years. Covered several desktop platforms and programming languages. Since 2003 working for Resco on mobile technologies – Palm OS, Windows Mobile, Windows Phone 7, Android. You can contact me at jano (at) resco (dot) net.

2 thoughts on “Migrating to Mango – Developer View. Part 3

  1. Pingback: Migrating to Mango – Developer View. Part 3

  2. Pingback: Migrating to Mango – Developer View. Part 3 – www.nalli.net

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s