Add a WinRT rid
Can we add a RID for platforms that support WinRT native APIs?
Our scenario:
Our package:
Microsoft.Data.Sqlite
runtimes/
win7-(bitness)/
native/
sqlite3.dll <-- win32 version
For UWP apps, this causes problems (see https://github.com/aspnet/Microsoft.Data.Sqlite/issues/245) because NuGet tries to add the win7 native asset (win32) and this does not pass the Windows App Cert Kit which does not allow calls to win32 APIs.
Our workaround: We use an MSBuild script to replace the "wrong" sqlite3.dll (win32) with the right one, a version compiled for WinRT APIs instead.
<Target Name="FixResolvedSqliteNuGetPackageAssets" AfterTargets="ResolveNuGetPackageAssets">
<ItemGroup>
<WrongSqliteNuGetPackageAssets Include="$(MSBuildThisFileDirectory)..\..\runtimes\win7-$(Platform)\native\*" />
<ReferenceCopyLocalPaths Remove="%(WrongSqliteNuGetPackageAssets.FullPath)" />
<ReferenceCopyLocalPaths Include="$(MSBuildThisFileDirectory)win10-$(Platform)\native\*" />
</ItemGroup>
</Target>
Where the workaround fails: If Microsoft.Data.Sqlite is a transitive dependency, the MSBuild target does not run. We cannot fix the incorrect NuGet resolution.
A WinRT rid Ideally, we'd like to drop the MSBuild hack altogether and have a package like this:
Microsoft.Data.Sqlite
runtimes/
win7-(bitness)/
native/
sqlite3.dll <-- win32 version
winrt-(bitness)/
native/
sqlite3.dll <-- winRT version
UWP and other WinRT compatible platforms would get the WinRT native asset instead of the Win32 asset.
cc @ericstj @yishaigalatzer
If we wanted to do that it'd require a template change in Visual Studio as well as a msbuild targets change in NuGet in addition to adding the RID to the RID graph. /cc @Pilchie @jasonmalinowski
Can you workaround this by putting the native library under runtimes/{rid}/lib/uap10.0. Lib and native under runtimes aren't treated any different by msbuild based projects.
Does nuget support this folder structure for native assets? runtimes/{rid}/native/{tfm}/ I didn't see this in https://docs.nuget.org/create/uwp-create#native-light-up
No, but as I mentioned lib and native are treated the same for UWP projects. They just give you some flexibility of having different asset types.
Lib and native under runtimes aren't treated any different by msbuild based projects.
True for now, but I'm not sure I can rely on that always being true in future version of msbuild.
Native is the TFM, so it doesn't support a TFM after it. The paths are runtimes/{rid}/native/ and runtimes/{rid}/lib/{tfm}/
Ok, workaround possibilities aside, is adding a WinRT rid something we can consider?
That's more of a request for VS and Windows folks since the complicated / breaking changes are on the templates side and targets side. I personally don't see a lot of value in doing this since the TFM is sufficient to qualify here. If we started having multiple different TFMs/AppModels with the same APPX bit requirement then it might make sense to add a distinct RID heirarchy.
cc @davidfowl
So would it be better to add support for runtimes/{rid}/native/{tfm}/ to NuGet?
From discussion with @emgarten, at the moment runtimes/{rid}/native/ adds native assets to all TFMs, (e.g. Win32 ends up in WinRT output), but if we moved native libraries to runtime/{rid}/lib/{tfm} then p/invoke stops working with dotnet run because it only probes runtimes/{rid}/native for native assets. So we're stuck.
From NuGet's point of view native dlls can exist in runtimes/{rid}/lib/{tfm} the native folder is a used to add an assembly in addition to the lib folder.
@ericstj @davidfowl is there a requirement that native dlls be under the native folder? It would be nice to clarify on how this should work and how build should handle this.
That might be a reasonable alternative. If the dependencies is indeed on WinRT surface you're better off with a TFM/TxM because WinRT has a more granular continuous version that represents the API surface and that's encoded in the TFM. I don't think we want to be in the business of shipping new RIDs everytime Windows rev's windows.winmd, and having folks rewrite their project.jsons.
DotNET run doesn't need to load the WinRT version. If you could come up with a scheme that would give CLI the right version using native and give netcore50 the right version (without duplicates) that would be sufficient.
@emgarten I believe CLI/host requires native DLLs to be in the native folder since the host needs to treat these differently than managed DLLs. Correct @schellap?
@ericstj the host relies on the package relative asset path specified in the app.deps.json which comes from project.lock.json, the host doesn't by itself enforce any path rules. The RID information for the asset also comes from the deps file.
Example:
"runtimeTargets": {
"runtimes/debian-x64/native/libuv.so": {
"rid": "debian-x64",
"assetType": "native"
},
"runtimes/osx/native/libuv.dylib": {
"rid": "osx",
"assetType": "native"
},
@natemcmaster do you have a repro of:
but if we moved native libraries to runtime/{rid}/lib/{tfm} then p/invoke stops working with dotnet run because it only probes runtimes/{rid}/native for native assets. So we're stuck.
The host however expects TFM be resolved before publish, example: runtimes/{rid}/native/netstandard1.3/, then the host would simply just do a rid-fallback starting from its own rid to match app.deps.json's runtimeTargets.{asset-path}.rid (above) to come up with the path: $APP_BASE/asset-path of rid-matched runtimeTargets
Here is the sample which contains libuv in this pattern:
https://gist.github.com/schellap/547edf55982a9c826891a96d64c5233d
@schellap on windows, if sqlite3.dll is in "runtimes/rid/lib/tfm", the lock file produces
"runtimeTargets": {
"runtimes/win7-x64/lib/netstandard1.0/sqlite3.dll": {
"assetType": "runtime",
"rid": "win7-x64"
}
}
This means the deps file gets "assetType": "runtime" as well, so p/invoke doesn't find the native library.
Unhandled Exception: System.DllNotFoundException: Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Should this be a bug on CLI? Seems to me this expected behavior since dll files in "runtimes/win7-x64/lib/netstandard1.0/" are expected to be managed.
@anurse could you confirm that CLI uses the asset sub-path to actually detect runtime/native assetType?
If I manually change project.lock.json to assetType native, p/invoke finds sqlite3.dll just fine.
"runtimeTargets": {
"runtimes/win7-x64/lib/netstandard1.0/sqlite3.dll": {
"rid": "win7-x64",
"assetType": "native"
}
}
From NuGet's point of view native dlls can exist in runtimes/{rid}/lib/{tfm} the native folder is a used to add an assembly in addition to the lib folder.
The problem is NuGet treats it as a managed library, even though it is a native binary, because it lives in lib
The problem is NuGet treats it as a managed library even though it is a native binary because it lives in lib
I wouldn't say NuGet is treating it as anything here. AssetType just refers to the lock file section it would be under if this were in a runtime target graph. The actual type of the assembly could be anything based on how the /lib folder worked before when there was a /native and /runtimes folder.
If it is the case that package authors need to separate out native vs managed assemblies when adding them under the /runtimes folder then I agree that NuGet needs to add support for /runtimes/{rid}/native/{txm}/
dotnet build is still going to have trouble with older packages where a user has added native dlls under the /lib/net40 folder. NuGet isn't going to start inspecting assemblies to determine the actual type for build. It seems like build should handle this scenario and do more to detect the type.
dotnet build is still going to have trouble with older packages where a user has added native dlls under the /lib/net40 folder
That's OK, the CLI host isn't going to work for "net40" apps, it's for Core apps, right? Even if someone "imports" one of those into a core app I don't think it's reasonable to expect that to work.
I feel like we're settling on adding /runtimes/{rid}/native/{txm}/ to NuGet. So I'm closing this and opening a NuGet issue.
Thanks @ericstj