user1413403
user1413403

Reputation: 61

Compiling Portable Class Library at run-time

In the example below... instead of compiling for .Net "v4.0", what should be provided to compile a PCL library?

var compiler = new CSharpCodeProvider(new Dictionary<string, string>
{
   {"CompilerVersion", "v4.0"}
});

Upvotes: 6

Views: 208

Answers (2)

Adam Scroggin
Adam Scroggin

Reputation: 124

I don't think you "tell" the C sharp compiler to compile something as a PCL. Instead, this information in embedded inside the .csproj file. For example, if you edit the .csproj and add the guid {786C830F-07A1-408B-BD7F-6EE04809D6DB} for the project type, it will be compiled as a PCL.

This site defines a lot of the guids: http://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs

Upvotes: 0

Daniel Plaisted
Daniel Plaisted

Reputation: 16744

From this perspective a Portable Class Library is simply a library that is compiled against a set of portable reference assemblies, instead of the implementation or reference assemblies for a specific framework.

You can see the path to the PCL reference assemblies if you create a PCL in Visual Studio, select the ".NET Portable Subset" reference in solution explorer, and look at the Path property in the properties window. (The path will be different depending on what set of platforms you target in the PCL).

Set the references that the compiler will use to all the DLLs in the PCL reference path, and the result should be a portable library. If there are references that are included by default (ie mscorlib), then you will also need to disable them.

Upvotes: 2

Related Questions