Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any guidance on converting existing .NET class libraries to portable libraries?

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?

like image 231
Mark Stafford - MSFT Avatar asked Jun 29 '12 15:06

Mark Stafford - MSFT


People also ask

What is portable class library in C#?

The Portable Class Library project enables you to write and build managed assemblies that work on more than one . NET Framework platform. You can create classes that contain code you wish to share across many projects, such as shared business logic, and then reference those classes from different types of projects.

How do you create a new .NET class library called member data?

Right-click on the solution in Solution Explorer and select Add > New Project. On the Add a new project page, enter library in the search box. Choose C# or Visual Basic from the Language list, and then choose All platforms from the Platform list. Choose the Class Library template, and then choose Next.

What is class library in asp net?

A class library is a pre-coded object-oriented programming (OOP) template collection. Both web and desktop applications use class libraries. Class libraries contain code for graphical user interface (GUI) elements such as buttons, icons, scroll bars and windows as well as other non-GUI components.


2 Answers

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.

like image 108
DerDani81 Avatar answered Oct 21 '22 18:10

DerDani81


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.

like image 39
Martin Poehler Avatar answered Oct 21 '22 20:10

Martin Poehler