There seems to be quite a bit of content out there for porting Windows Phone apps to Metro, but what about if you're starting from scratch and you want to build an app that runs on both platforms?

As I understand it, Windows Phone dev uses VS2010 on Win7, but Metro dev requires VS2012 RC on Win8. Is there a way to work on both at the same time? Does the Windows Phone SDK run OK on VS2012 on Windows 8?

Is it possible to have projects for both apps (and a separate project for shared code - in a Portable Class Library?), in the one solution?

2 Answers
2

I haven't got an environment to do this myself, so this will be at best a partial answer based on Internet research, plus some experience of my own that might be relevant.

According to this and other sources, VS2012 RC cannot be used with the current Windows Phone SDK, which continues to require VS2010. The exception to this is (as you mentioned) Portable Class Libraries, which do seem to be able to create libraries compatible with Windows Phone 7+. To consume these, however, in an actual WP7 app, you would need to reference them in a proper WP project back in VS2010. So if a PCL isn't sufficient for your needs, and you want actual target-specific projects with shared code, VS2012 alone wouldn't be an option.

But, there are a few more pieces to this story which may be of interest, and which may help you.

The first is the VS2012 addition of solution and project backward compatibility. VS solutions can contain projects even if they aren't loadable by the version of VS you are using, which means that you could perhaps construct a solution which would contain a VS2012 Metro project and a VS2010 WP7 project at the same time. In either case, the project would fail to load (I assume) depending on what version of the tools you are using.

The reason this might still be valuable is that you can ALSO create projects which share code such that the same codebase is compiled to normally-incompatible project types even if they aren't Portable Class Libraries.

The way it works is, you create your code files either independently of any project or using some given type of project as a baseline, then link the code files into other projects and . In this case, you'd probably want a VS2010 WPF or Silverlight 5 project, since both versions can open these projects. Then, create your Metro and WP7 projects alongside this one (with no code, at first). Next, you use the Solution Explorer's Add Existing Item dialog to select the files from your baseline project (but do not click Add yet). Click the down arrow next to the Add button and you will have the option to Add As Link, which is what you want.

Repeating this process in both projects will allow any code or assets you develop in one version to flow through to the other. Additionally, if you need to modify or debug the baseline files, you can do so in either version of VS, because the baseline project works the same in either.

The last part of this story is, you can use conditional compilation symbols and #if preprocessor directives to further tweak any shared code that simply must diverge according to target. This should be used sparingly, however, for everyone's sanity.

I have actually shared code between WP7, Silverlight, and other projects in this way in VS2010, and it works quite well where required.

So, you will still need to switch IDEs to compile and deploy your Metro apps and WP apps, but in theory I think there's a good deal of synergy you can, in fact, squeeze out of VS even in its current form.

New information today

At the Windows Phone Summit in San Francisco today, Microsoft announced that Visual Studio 2012 would be able to write apps targeting Windows 8 and also Windows Phone 7.5/8. This would seem to change the information given above and provide an obvious and easy solution. So you don't have this yet, but watch for it in the future.

One approach, such as that used by at least one open source project is to use linked source files, to share what can be shared, and branch what needs changing. That seems like a simple approach, and will allow maintenance across all platforms.