Is .NET for Universal Windows Program a subset of

2019-01-23 20:50发布

问题:

My confusion is I read that UWP uses .NET Core, but there's a separate ".NET for UWP" API documentation here. Also, I can't find some .NET Core features in my UWP project.

回答1:

.NET Core is a cross-platform subset of .NET that can be use to build apps for Windows, Linux, Mac, and yes, UWP.

UWP Api is also a subset of the .NET API, which can run on .NET Core. It also has a number of API's that are unique to UWP. UWP apps can be .NET core apps, but the reverse is not necessarily true. Not all .NET core apps are UWP apps.

Just like there are API's for .NET Core that only apply to Linux, or Mac.



回答2:

No, UWP is a distinct api that targets a different windowing model, replacing large parts of the traditional winapi. You get a .NETCore dependency because the project templates in VS select it. For a good reason, you can get the U in UWP (Universal Windows Platform) only from .NETCore, devices like phones and Hololens don't have the full .NET framework version available. Trying to be competitive in mobile applications was a core reason for UWP.

UWP is a COM based api, basic reason why it works with languages like Javascript and C++. Otherwise very well hidden, the traditional type library format of COM was replaced with .winmd, a format that is heavily based on the metadata format of .NET. It can emulate features that COM cannot support, like generics, static methods and implementation inheritance. The language projection that's required to get this emulation is built into the CLR. Not much they could do to make exceptions work better.

You can use a UWP api in a desktop app as well. Microsoft doesn't encourage that so you get no help from a project template. Easy to fix with a text editor, add <TargetPlatformVersion>10.0.10586.0</TargetPlatformVersion> to your .csproj file and now you can use Project > Add Reference and select a UWP contract. Handy to take advantage of the device namespaces.



回答3:

Straight Answer: No it is not!

Long Answer: It's complicated

  • uap10.0 (UWP) and netcoreapp1.0 (cross-platoform .NET Core) are competing app models / SDK / Platforms (whatever terminology Microsoft chooses to mention next). I use the target framework monikers (the technical terminology) here onwards to avoid confusions around the term ".NET Core". uap10.0 focus on Windows based UI applications and netcoreapp1.0 is basically console applications for cross platforms (which like any programs can run servers, like ASP.NET).
  • The superset / subset question is tricky. They overlap. uap10.0 implements the netstandard1.4 and netcoreapp1.0 implements the netstandard1.6 (which is a strict superset to netstandard1.4) (platform standard documentation). However, both application models add significant additional libraries to it (uap10.0 adds e.g. the Windows.* libraries, while the library for netcoreapp1.0 called Microsoft.NETCore.App (NuGet) adds stuff like immutable collections, networking, filesystem, cryptography and other things which are not standardized (yet) across the .NET implementations).
  • The terminology ".NET Core" is basically screwed up. The CLR which runs uap10.0/UWP was derived from Silverlight which labelled its runtime coreclr. The modern cross platform netcoreapp1.0 uses a CLR derived from the UWP project. The same is true for the libraries which in all cases are System.Runtime based instead of mscorlib based.