简体   繁体   中英

Can PCL libraries run with ASP.NET MVC?

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: 在此输入图像描述

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM