简体   繁体   中英

C++ Universal Windows DLL for both UWP and Classic Desktop

Is the Universal Windows dll actually universal, or is it just for UWP?

I am building a native C++ dll with all the defaults, but when I reference it from a Classic Desktop app (it is a unit test), then I get this exception:

This operation is only valid in the context of an app container.

Of course, the "Universal" in "Universal Windows" may be for the cool guys out there :), but I don't really want to build two separate dlls for Windows 10, just because.

I also noticed this when building NuGets for .NET Core, I stuck my native library in the win10 folder. I also have a special build for Windows 7, so that went into the win7 folder. All looked good, until runtime, not even .NET Core can load this universal dll.

Is the C++ Universal Windows just for UWP? Is there a way to use a single dll for .NET Core, UWP and Classic Desktop? Any special flags to set?

If there is no way to have a true universal dll, how does one distinguish if a Windows 10 dll is for UWP or Classic Desktop?

I had a discussion with the NuGet team, and they have a solution:

Support for runtimes/{rid}/nativeassets/{tfm}/{any?} was added with #2782

Set a min client version of 3.5.0 in your nuspec to ensure that consumers have the correct client version to pick up this nupkg path.

https://github.com/NuGet/Home/issues/5042

So in the case of my .nuspec:

<file src="Managed.dll" target="lib\netstandard1.3" />
<file src="Native-Win7.dll" target="runtimes\win7-x64\native" />
<file src="Native-Win10.dll" target="runtimes\win10-x64\native" />
<file src="Native-Uap10.dll" target="runtimes\win10-x64\nativeassets\uap10.0" />

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