Reputation: 1174
Can Portable Class Libraries be used for simple classes that contain function libraries and no UI components?
Is it possible to write a non-UI class library and share it across multiple platforms?
Upvotes: 1
Views: 132
Reputation: 1500835
Can Portable Class Libraries be used for simple classes that contain function libraries and no UI components?
Absolutely, although the more modern alternative to PCLs is .NET Core libraries. PCLs had various issues in terms of tooling and working out which profile you needed to use: the .NET Core model is much simpler. (There have been a few twists and turns along the way, with project.json
etc, but the final .NET Core SDK is now out... You'll want Visual Studio 2017 to develop with it.)
Is it possible to write a non-UI class library and share it across multiple platforms?
Absolutely - that's precisely what projects like Noda Time and Json.NET do. (Disclaimer: I'm the main author of Noda Time, so I'm clearly biased :))
There's a bit of subtlety here, in that portable projects are often distributed as NuGet packages, but there can be multiple different assemblies in the NuGet package, targeted at different frameworks. For example, Noda Time 2.0 targets netstandard1.3
and net45
- the netstandard1.3
assembly doesn't have support for binary serialization or as much support for TimeZoneInfo
as the net45
assembly.
Upvotes: 1
Reputation: 63203
I see Jon Skeet kindly answered the two in main body, so I will only focus on "Are Portable Class Libraries for Xamarin only?"
When Microsoft came with the PCL idea after they shipped .NET Framework 4.0, they were aiming to share code among .NET Framework/Silverlight/Windows Phone and so on. In fact they did not have Xamarin in mind at the very beginning. They definitely knew Mono and Xamarin though.
PCL requires CLR to support retargetable class metadata, which at that time was planned for .NET Framework 4.5 and above. Microsoft did back port the necessary bits to .NET Framework 4.0, which later shipped as a patch.
Probably with some help from Microsoft, Mono/Xamarin was later able to improve their CLR implementation so that PCL assemblies can be consumed. They even got help from Microsoft to release PCL reference assemblies for Linux and Mac, so you can compile projects against them.
PCL profiles, such as "portable-net45+netcore45+MonoAndroid1+MonoTouch1" were added after the initial release, and similar changes were also made to NuGet, so that Mono/Xamarin became officially part of the .NET ecosystem (while they in fact had been there for years).
Now, you should simply forget PCL, and embrace .NET Standard. It is the new way, and is much simpler to use.
Upvotes: 1
Reputation: 2628
watch this links:
When you create a Portable Class Library, however, 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.
https://msdn.microsoft.com/en-us/library/gg597391(v=vs.110).aspx https://www.codeproject.com/Articles/647001/What-are-portable-class-libraries
Upvotes: 1