Geeks With Blogs
Igor Milovanović .NET, cats and more...

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.

image

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:

image

 

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: http://nitoprograms.blogspot.de/2012/05/framework-profiles-in-net.html

Posted on Friday, August 31, 2012 4:55 PM | Back to top


Comments on this post: VS2012 - How to manually convert .NET Class Library to a Portable Class Library

# re: VS2012 - How to manually convert .NET Class Library to a Portable Class Library
Requesting Gravatar...
is it possible to convert visual studio 2008 class library to a portable class library
Left by prashanth on Jun 18, 2014 12:18 PM

# re: VS2012 - How to manually convert .NET Class Library to a Portable Class Library
Requesting Gravatar...
This is not enough, not for VS 2013 anyway. You also need to add a valid <TargetFrameworkProfile> (Portable24 in my case, copied it from an existing PCL).
Left by Dimitar Dobrev on Jun 26, 2014 1:42 PM

# re: VS2012 - How to manually convert .NET Class Library to a Portable Class Library
Requesting Gravatar...
1)Create a new project of the desired type - call it template.
2)Unload it and edit project properties
3)Unload the target project to be converted and edit project properties
4)copy paste probably everything inside the first propertygroup (please double check) except
a)ProjectGuid
b)RootNamespace
c)AssemblyName
Might require some more tweaks based on the source and target framework versions.
Left by Jay on Feb 24, 2015 1:58 PM

Your comment:
 (will show your gravatar)


Copyright © Igor Milovanovic | Powered by: GeeksWithBlogs.net | Join free