I took over a Windows Phone project which was previously targeting WP 7.1 platform, and with the recent announcement of the new platform it should target WP 8 as well.
My VS 2010 solution consists on several projects (Data access, Model, Tests and WP7 client app) and i am wandering on how to include support for WP8.
I have to note that the code-base is not compatible with WP8, due to usage of Toolkit controls and other 3rd party libraries targeted for WP7.1 specifically.
Also there is another problem with the Visual Studio versions - WP7.1 can work with VS 2010, but WP8 requires VS 2012. Should i move the whole code-base to VS 2012?
Any good advice on how to organize code-base in a most meaningful way in order to avoid duplication and possible painful maintenance?
I am thinking between one solution - multiple projects vs. multiple solutions - reusable projects approach. Code duplication (like two separate folders/solutions) should be the least possible approach (fallback).
The best thing to do is for you to upgrade all the projects to VS2012 in order to be able to support both WP versions (you'll still be able to open the WP7 project in VS2010 despite it being a VS2012 solution, 'cause it's backward compatible).
Regarding the best way to organize the code base, in my opinion you should create a Portable Library that supports both WP7 and WP8 and get all the common code base there (probably mainly the business logic, specially good if you're using a pattern such as MVVM). Not forgetting about the controls issue, you should probably have some different controls for WP8 'cause the screen sizes are not the same and you could get some more info available and use different controls. If you still want to use the same XAML code, have just one file in one of the projects and add that same file "As Link" in the other project you want to re-use it.
Finally, you can, and also probably should, use some conditional code compilation by making use of the #if directive.
Hope that this information helps, and if any code sample is needed, just say so and I'll try to gather something up.
来源:https://stackoverflow.com/questions/13799646/how-to-organize-windows-phone-code-base-to-target-both-7-x-and-8-platforms