Of course with the announcement of Windows Phone 8.1 XAML applications (ie applications for WP8.1 written in Windows XAML) and support for Universal applications, not everyone is going to immediately rebuild their Windows Phone application. Instead, existing developers need a mechanism to upgrade to the new runtime to leverage the new features without having to redeveloper all their pages. This is where Silverlight 8.1 applications come in.
There is only minimal support within Visual Studio to support developers upgrading to Silverlight 8.1, allowing them to “Retarget to Windows Phone 8.1”.
Retargeting works well and typically your application will continue to run. However, in most cases you’ll want to maintain both a Silverlight 8.0 and 8.1 versions of your application. An alternative is to create a copy of your Silverlight 8.0 application and upgrade that – now you have two versions of your application that you have to support. Luckily this is an area where the new Shared project support, added to enable universal applications across Windows Phone and Windows, can be used to maintain code that is used by both a Silverlight 8.0 and 8.1 application (sort of Linked files on steroids).
- Install the Shared Project Reference Manager (http://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450) – this makes creating Shared Projects much easier
- Create a new Shared Project eg MyApplication.Shared
- Unload you Windows Phone project
- Edit your Windows Phone project file
- Add a Shared Project Reference via the right-click shortcut menu on your Windows Phone project (Note: for some reason adding a shared project reference isn’t supported for Windows Phone projects, so we need to do it the manual way)
- Add Import to end of project file which references the shared project file eg
<Import Project="..\MyApplication.Shared\MyApplication.Shared.projitems" Label="Shared" />
- Reload your Windows Phone project – you should see a reference to your Shared project under References node
- Move as many files as possible from your Windows Phone project into the Shared project
- Note that you may experience some of these issues:
> AppResources.resx doesn’t move easily. You’ll need to make sure that both the resx and the designer.cs file are moved and that the Build Action is correct (resx file should have a Build Action of Embedded Resource and a Custom Tool of PublicResXFileCodeGenerator). You also need to remove the “.Resources” from the name of the resource being loaded and the namespace.
> You need to keep any images referenced in the WMAppManifest.xml file in the Windows Phone project. This is ApplicationIcon.png and FlipCyleTileMedium.png by default
> You still need an App.xaml file in your Windows Phone project
- Check that your Windows Phone application builds and runs (fix any build errors!)
- In Windows Explorer take a copy of your Windows Phone application and rename the folder and project files eg MyApplication.SL81
- Add the copied project into the same solution
- Right click on the project you just added and select “Retarget to Windows Phone 8.1”. Your solution structure should now look similar to the following
- Build and run your new Windows Phone 8.1 application
The upshot after all this is that you have a Shared project where you can store shared files across your Windows Phone Silverlight 8.0 and 8.1 applications.