In this article we are going to see how we can build an app that target only Windows Phone Version 7.1 or only Windows Phone 8.0 or both the versions with out much of creating code base. This approach is much needed when we develop apps targeting the SDK of which the application should be developed and showcased in the Market. So the default option to do is to have 2 separate versions of Windows Phone Project code base of targeting each version separately which will be more painful in maintaining the application as a single change should affect in both the source code. [more]
Let us see how we can achieve this task by building a common Class Library that can be shared across the different project versions so that changes that affect in the single class library will be affected in both the versions of the application. Open Visual Studio 2012 IDE in administrator mode and create a new project for Windows Phone which is targeting Windows Phone 7.1 version as shown in the screen below.
Clicking on OK will create the project and the solution with the list of default files and folders that are required to run the application. It will take some time to create these files based on your system configuration, so once everything is ready we can see the Visual Studio IDE with the project as shown in the screen below.
Right click on the Solution and click on Add –> New Project to open the add new window to add a Windows Phone Class Library which can be used to place all the business logic that can be shared across the different versions as shown in the screen below.
Click on ok will popup a window to select the version we planned to target, just select the base version Windows Phone Version 7.1 from the available list as shown in the screen below.
Now clicking on OK will create the base class library in which we can refract the code that are much needed to share in both the application projects. Refer the class library in the base application project which we created targeting the Windows Phone 7.1 version as shown in the screen below.
Next step is to use the same code base (shared library) in the Windows Phone application that targets version 8.0, Click on the project solution and click on Add new project to create a new Windows Phone application which targets 8.0 version and refer the same shared class library. This approach will avoid to make changes to the business requirement in both the project application targeting the different versions of the OS.