VS2012 – How to manually convert .NET Class Library to a Portable Class Library

The portable libraries are the  response to the growing profile fragmentation in.NET frameworks. With help of portable libraries you can share code between different runtimes without dreadful

#ifdef PLATFORM

statements or even worse “Add as Link” source file sharing practices.

If you have an existing.net class library which you would like to reference from a different runtime (e.g. you have a.NET Framework 4.5 library which you would like to reference from a Windows Store project), you can either create a new portable class library and move the classes there or edit the existing.csproj file and change the XML directly. The following example shows how to convert a.NET Framework 4.5 library to a Portable Class Library.

!

First Unload the Project and change the following settings in the.csproj file:

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

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

and add the following keys to the first property group in order to get visual studio to show the framework picker dialog:

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

After that you can select the frameworks in the Library Tab of the Portable Library:

!

As last step, delete any framework references from the library as you have them already referenced via the.NET Portable Subset.

[1] Cross-Platform Development with the.NET Framework – http://msdn.microsoft.com/en-us/library/gg597391.aspx

[2] Framework Profiles in.NET: 

This article is part of the GWB Archives. Original Author: gwbarchive

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.