1

Fist of all I want to say that I've read these two discussions: How to organize Windows Phone code base to target both 7.x and 8 platforms and Windows Phone 7/WPF - Sharing a codebase. So, I know about Portable Class Librariy project type which might be an answer to my question. But it isn't an answer for my case.

Problem

I have some old code-base in my project WindowsClassLibraryNetFw35. I need this project to be a class library which targets .NET Framework 3.5. The reason for it is that some dependent applications are deployed on customers' machines which don't have .NET Framework 4+ installed. Unfortunately I can't force my customers to upgrade their environment.

Now I create new project(s) for Windows 8 and Windows Phone 8. As you know, Windows Phone 8 projects will fail when I attempt to reference my old library because it is not a compatible Windows Phone project (see screenshot). enter image description here

Question

What is the best way to reorganize my project type(s) in order to be able to support both my old and new projects?

Community
  • 1
  • 1
Igor Soloydenko
  • 11,067
  • 11
  • 47
  • 90

1 Answers1

2

I would still aim to get a PCL working, but if that fails, you can use the same code in two different projects.

Create two different projects, one Windows Phone, the other a Windows Store App. Add a file to one, then add that other file as a link to the other project. This means you have a single source file between two different projects, but will be compiled with each respective runtime tools. Then you can do things like this in your code:

void Foo()
{
    #if WinRT
        //WinRT specific code here
    #elif WindowsPhone
        //Silverlight specific code here
    #endif
}

Just add the respective compiler constants on the Build tab of your Windows Phone and WinRT projects. This is far a more tacky solution, but sometimes its the only approach that works.

vcsjones
  • 138,677
  • 31
  • 291
  • 286
  • Thanks! Well this solution isn't new for me. The problem is that there is no easy way to introduce these files in every new project I create. It will take a lot of time to add these files, right? May be I could create a `*.csproj` template which will contain all the files from a library project(s). That approach also has a problem. If I add a new file to the library project, I need to add a link to it in every already existing client project and update the `csproj` template. What I'm trying to say that it seems to be a lot of rut boring actions which disturbing me from development process. – Igor Soloydenko Dec 30 '12 at 21:49
  • @keykeeper Unfortunately I think this is all there is. You may be able to develop a tool that aides this process, but the "solution" is use .NET 4.0 and PCL. – vcsjones Dec 30 '12 at 23:02
  • I CAN'T use PCL because some of my old projects target .NET Framework 3.5 and I can't force clients to update it to version 4. – Igor Soloydenko Dec 31 '12 at 06:08