53

I have some class libraries with a non-trivial amount of existing code. The class libraries currently target .NET 4.0. Is there any guidance on how to convert these libraries to be portable libraries? From looking at the .csproj, it doesn't appear that there are a lot of differences:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />

and

<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Is it a good or bad idea to try converting an existing class library to be a portable library?

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
Mark Stafford - MSFT
  • 4,306
  • 3
  • 17
  • 23
  • Igor Milovanović has a nice tutorial with visuals [here](http://geekswithblogs.net/imilovanovic/archive/2012/08/31/vs2012---how-to-manually-convert-.net-class-library-to.aspx). – Todd Menier Mar 23 '14 at 15:33

3 Answers3

67

We also converted existing libraries to portable libraries and it works fine. You have to modify the project file. Replace the following line:

<Import Project="..." />

with

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />

Add following line inside a PropertyGroup tag

<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

And remove following lines from the AssemblyInfo.cs file

[assembly: ComVisible(false)]
[assembly: Guid("...")]

After that, Visual Studio should show you the Tab page "Library" in the project Property page and you can change the target frameworks for the portable library.

Anthony Mastrean
  • 21,850
  • 21
  • 110
  • 188
DerDani81
  • 987
  • 11
  • 24
4

I created a Visual Studio Extension to automate this. Just search in Visual Studio > 2012 in Extension for "convert to pcl"

The source code is also available on Github.

trinaldi
  • 2,872
  • 2
  • 32
  • 37
0

You can delete the <Import Project="..." /> line. Then, when you reload the project, Visual Studio will ask you which frameworks to target. You can then change this later in the project's properties.

Owen Johnson
  • 2,416
  • 2
  • 19
  • 23