Can PCL libraries run with ASP.NET MVC?

990 views Asked by At

I wish to write a library that can run on a number of targets such as WPF, Windows Phone/Mobile, Mono, and ASP.NET. I keep searching for information on this but it seems PCL's are not supported in ASP.NET?

Even VS indicates PCL can't be used with ASP.NET: enter image description here

So what should I do to be able to write a PCL that runs on all the platforms? Use PCL for everything apart from ASP.NET, and create a normal Class Library for ASP.NET and basically copy+paste the code?

1

There are 1 answers

1
Jaanus Varus On BEST ANSWER

The short answer is YES, as long as the PCL profile supports the same .NET framework version your MVC application is targeting, you will be fine.

When you create a Portable Class Library, you can choose a combination of platforms that you want your code to run on. The compatibility choices you make when creating a Portable Class Library are translated into a "Profileā€ identifier, which describes which platforms the library supports.

What probably confused you, was the fact that ASP.NET was not mentioned in the list of supported software frameworks (platforms). The reason is that ASP.NET is not really a software framework, but an application framework (higher level). This means that whatever application frameworks target the software framework the PCL supports, the application frameworks will also work.

Be sure to take extra caution when choosing the supported platforms when creating a new PCL project, since the API that is available for use in that project depends on that choice!

You can read more about portable class libraries on MSDN.