How to reference Windows.winmd from a .NET Core library?

ぐ巨炮叔叔 提交于 2019-11-29 12:53:56

The framework moniker (TFM) are a bit confusing.

The Profile 32 targets "Windows 8.1, Windows Phone 8.1" (=platform standard of 1.2).

The lower the standard, the more platforms can consume the class library, but they have the fewest features. The higher the standard, the more features can be used, but the platforms may be limited.

So if you want to support/use a winmd in your "Class Library (package)", you need to use the net (when targeting the full .NET framework) and dotnet (when targeting the .NET core framework) monikers.

From the .NET platform standard link above:

Exising PCL projects in VS2013 and VS2015 (excluding UWP targets), can only target up to .NET Platform Standard version 1.2.

I'm not sure if this also applies to .winmd files. But somethings you could try is to target dotnet51, dotnet52 or dotnet53 for .NET Core. You can't use .NET 4.6 (dotnet54 and dotnet55 monikers) and still target Windows 8.1, this will only work for UWP. According to a post of Marc Garvell the versions are off by one (so dotnet51 equals netstandard1.0 and dotnet5.5 equals netstandard1.4)

It seems that the names of the monikers are for the upcoming ASP.NET Core 1.0 RC2 version and for current RC1 you may still have to apply the dotnet monikers.

Of course you can target multiple frameworks (for each framework defined, one assembly will be compiled), but you'll have to use preprocessor directives to remove your winmd/win8.1 classes from your code and replace it with something that works on the newer platforms.

Remember, that for Class Library (Package) you have to use "net" and "dotnet" moniker, while for .NET Core applications and test projects you still use "dnx" and "dnxcore".

Right now it's a mess, but it should be much better with the next RC2... I hope

James Ko

Well, looks like I found the answer.

The trick was to base your project off csproj instead of xproj, which you can do by following the steps here.

Once you've done that, just go to your project's properties and retarget the lib to Windows 8.1 and Windows Phone 8.1. Then you'll see the little assembly icon for Windows pop up, like this:

Add reference to Microsoft.Windows.SDK.Contracts in netcoreapp3.0 library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!