21

I currently have a Portable Class Library whose code is entirely compatible with a regular Class Library without any modification.

I was wondering if there was an existing software to do the conversion automatically ; I looked into the Visual Studio tools but could not find any suitable. Before writing my own I just wanted to be sure!

Max
  • 3,453
  • 3
  • 32
  • 50
  • 4
    If the code is entirely compatible, why do you want to convert it? Just use the PCL as-is in your own project. – thecoop Nov 20 '13 at 11:04
  • I use an old version of Xamarin which does not support PCL. – Max Nov 20 '13 at 11:18
  • Is "recompile it for a different target" an option? Or are you trying to work at the dll level? If so: is it signed/strong-named? – Marc Gravell Nov 20 '13 at 11:46

2 Answers2

56

The differences will be in your .proj file.

Having tried it myself you will have to do all of the following;

  1. Remove the <TargetFrameworkProfile> element
  2. Remove the <ProjectTypeGuids> element
  3. Change where you have #2 (below) for what I shown in #1

1. Regular class library

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

2. Portable class library

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
obaylis
  • 2,904
  • 4
  • 39
  • 66
  • You also need to remove all references to non pcl dll like System etc. – Jan Zahradník Feb 09 '15 at 14:03
  • 4
    I think that should be you need to *add* references to things like System and System.Core when going from PCL to normal. (which is what it sounds like the OP was asking) After the changes listed here, I had no references to anything, but it was easy enough to add them back. Thanks! – Steve In CO Mar 10 '15 at 23:35
  • Worked nicely. Thanks a lot. – AH. Feb 09 '17 at 07:33
  • Also need to set correct `targetFramework` in `packages.config` and restore packages. – Elan Hasson Mar 12 '19 at 22:47
6

Use VSCommands, it has as a build in functionality to convert Projects to PCL. Right mouse click on Project and convert. It´s free and part of Visual Studio extensions http://vscommands.squaredinfinity.com/Features-SolutionExplorer

Update 2016-10-12: Above link is dead. The tool has been rewritten for Visual Studio 2015 and can be found here: https://visualstudiogallery.msdn.microsoft.com/c84be782-b1f1-4f6b-85bb-945ebc852aa1

Tore Østergaard
  • 4,362
  • 3
  • 27
  • 43
Martin
  • 61
  • 1
  • 2
  • That's the opposite of what the author wanted to do. They already have a PCL and want to convert it to a regular class library. Also, the link is now broken. – Swampie Jun 21 '16 at 08:09