2
votes

Say, I have created and extended a Windows Phone Class Library (WPCL) project or any other Class Library project that targets a specific platform.

Say, I am now considering targeting another .NET platform, e.g., Windows Store, but at the time of creating my Class Library I chose to create a platform specific Class Library (such as my WPCL) and not a Portable Class Library (PCL).

The source code written is portable, it just requires a PCL project file (csproj).

From WPCL and PCL csproj comparison it seems that only a couple of properties differ. But do I need to hack the csproj to get the work done?

Basically, I want to know whether,

is there a way, to automatically convert a platform-specific Class Library into a Portable Class Library without hacking csproj files?

3
Well, you could just create a new project and use the same .cs files in each... there's a handy "include *.cs resursive" option available, which can make it maintenance free, if you likeMarc Gravell♦
@MarcGravell Are you talking about the "drag-and-drop" of files and folders from one project to another, pressing the ALT key while dropping? If this is what you mean, it could be good to point out that it is only "maintenance free" in terms of "dropped" files; if you later add new files to or remove files from the "source" project these modifications will not be reflected in the "destination" project.Anders Gustafsson
@Anders no, I meant what I said. You can add files to a csproj with a wildcard instead of as names - in a single folder or recursively. I use this in all of my multi-target work, so I only actually ever maintain the "core" project. The rest just use all the .cs files automatically. The wildcard is retained so it applies both now and in the future.Marc Gravell♦
Thanks for the clarification, @Mark, I didn't know this was possible. Is this described somewhere in the MSDN documentation?Anders Gustafsson

3 Answers

0
votes

No, there's not currently a way to do this. If your code is entirely portable I'd suggest switching to a PCL. I think he best way to do this is to create a new PCL project in the same folder, edit the portable .csproj and copy the items from your platform-specific project file, then delete the platform-specific project and rename the portable one to the same name as the old platform-specific one.

1
votes

I know you are asking for a non-hacking way, but as it is quite simple I post the solution anyway: http://geekswithblogs.net/imilovanovic/archive/2012/08/31/vs2012---how-to-manually-convert-.net-class-library-to.aspx

This works quite fine, but it doesn't seem to work perfectly for VS2013 anymore (It doesn't show you the change target dialog but only a dropdown box with all possible combinations). I played around a little bit and worked out how I can change a csproj to a portable library targeting Windows 8.1. I don't know if there are any side effects (and to be honest, I don't know exactly what I'm doing), but at least I can see no difference between my converted and the original portable libs and everything compiles fine.

replace the import statement (normally at the end of the document) with the following:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />

add the following tags to the first property group

<ProjectTypeGuids>{BC8A1FFA-BEE3-4634-8014-F334798102B3};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<TargetPlatformIdentifier>Windows</TargetPlatformIdentifier>
<TargetPlatformVersion>8.1</TargetPlatformVersion>

and finally remove the TargetFrameworkTag.

The project should now be a portable lib referencing Windows 8.1 - just change it to whatever you like now.

Note: I did not try, but I guess this only works for VS2013 (for 2012 use the link above).

1
votes

You can use following Visual Studio Extension to do this automatically.

After install choose "Tools > Convert projects to PCL" and select projects you want to convert.