简体   繁体   中英

Reference UWP library from .net standard class library

I have a solution with some projects:

  • client app - UWP project
  • device sdk - UWP project (because of bluetooth APIs)
  • client app - ASP.Net Core 1.1 targeting .Net Core 2.0
  • client app plugins
  • some projects with shared model and interface classes.

I would like to use .net standard projects as much as possible (for the shared projects and preferably for the plugins) because they are more lightweight and can be edited without unloading them in Visual Studio for example.

Referencing .net standard 1.4 libraries FROM an UWP project goes fine, but referencing an UWP project FROM a .net standard 1.4 project results in an error:

Project DeviceSDK is not compatible with netstandard1.4 (.NETStandard,Version=v1.4).
Project DeviceSDK supports: uap10.0.15063 (UAP,Version=v10.0.15063)

Is this is there any workaround for this?

That's simply impossible. A cross platform library won't be able to reference a platform specific one.

I refactored the interfaces and data models of the device SDK out of that project and create a .net standard DeviceSdk.Core project. This project can then be referenced from application logic projects and the DeviceSdk main project.

So the structure becomes roughly:

  • ClientApp - UWP project, referencing all projects but the ClientApp.Frontend project
  • DeviceSdk - UWP project (because of bluetooth APIs), referencing DeviceSdk.Core
  • DeviceSdk.Core - .net standard 1.4
  • ClientApp.Frontend - ASP.Net Core 1.1 targeting .Net Core 2.0, referencing ClientApp.Core
  • ClientApp.Plugins - .net standard 1.4, referencing ClientApp.Core and DeviceSdk.Core
  • ClientApp.Core (some projects with shared model and interface classes) - .net standard 1.4

.net standard class library can't reference UWP libs. That would break the whole concept of .net Standard.

The idea is that a class library that targets specific .net standard version can only reference limited set of APIs defined by the standard.

For example, .net standard v1.4 only allows API-s listed within this file: https://github.com/dotnet/standard/blob/master/docs/versions/netstandard1.4_ref.md

This list is frozen and is supposed to remain intact.

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