*Written for Visual Studio 2013 Update 2 RC release
The recently introduced Universal apps for Windows are a significant improvement on the previous level of code sharing available across XAML platforms. For the first time you can share not only PCL compliant .NET code but also a significant amount of XAML, and additional UI related assets like language resources. For MVVM apps this now can mean adding sharing of Views on top of shared Models and ViewModels that can be created with today’s PCLs.
Creating a Universal app starts with creating the new project type, in this case I’ll pick the Blank template.
From this template, you will get not one, but three project nodes created for you: the Windows 8.1 Modern app, the Windows Phone 8.1 app, and a completely new type – the Shared project. They’re all placed in a Solution (and also physical) folder to keep them together.
The Shared project is unique in that it has no build output of its own. It simply exists as a container for code and resources that are used by the other two projects which are linked to it. Each of the app projects shows a reference to the Shared project, which unlike a normal reference means that everything in the Shared project also belongs to them. This is handled through a new .projitems file type existing in the Shared project, which is essentially just a subset of a normal MSBuild project file.
A setup similar to this was possible before by using linked files across your different projects, but the Visual Studio experience is so much better here. Creating new assets is as simple as adding them to the Shared project, no extra linking step for each new file. You also get much more help in making code that works on both platforms. Although you can still use #ifdef directives to switch sections of code on or off by platform, far more of the code can stay the same and there’s no need to close and reopen files to get them in the correct platform context for Intellisense, errors, etc. A new dropdown shows up for any Shared project code files, allowing you to easily switch between contexts.
There’s lots more to explore with these new features but just the initial setup experience is already a huge improvement over the old way of sharing code between XAML apps.