Repository navigation
Description
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 aspnet/Microsoft.Data.Sqlite#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.
Activity
ericstj commentedon May 12, 2016
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.
natemcmaster commentedon May 12, 2016
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-upericstj commentedon May 12, 2016
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.
natemcmaster commentedon May 12, 2016
True for now, but I'm not sure I can rely on that always being true in future version of msbuild.
emgarten commentedon May 12, 2016
Native is the TFM, so it doesn't support a TFM after it. The paths are
runtimes/{rid}/native/andruntimes/{rid}/lib/{tfm}/natemcmaster commentedon May 12, 2016
Ok, workaround possibilities aside, is adding a WinRT rid something we can consider?
ericstj commentedon May 12, 2016
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.
natemcmaster commentedon May 12, 2016
cc @davidfowl
natemcmaster commentedon May 12, 2016
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 toruntime/{rid}/lib/{tfm}then p/invoke stops working withdotnet runbecause it only probesruntimes/{rid}/nativefor native assets. So we're stuck.emgarten commentedon May 12, 2016
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.
ericstj commentedon May 12, 2016
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?
schellap commentedon May 12, 2016
@ericstj the host relies on the package relative asset path specified in the
app.deps.jsonwhich comes fromproject.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:
@natemcmaster do you have a repro of:
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 matchapp.deps.json'sruntimeTargets.{asset-path}.rid(above) to come up with the path:$APP_BASE/asset-path of rid-matched runtimeTargetsschellap commentedon May 12, 2016
Here is the sample which contains
libuvin this pattern:https://gist.github.com/schellap/547edf55982a9c826891a96d64c5233d
natemcmaster commentedon May 12, 2016
@schellap on windows, if sqlite3.dll is in "runtimes/rid/lib/tfm", the lock file produces
This means the deps file gets
"assetType": "runtime"as well, so p/invoke doesn't find the native library.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.
schellap commentedon May 12, 2016
@anurse could you confirm that CLI uses the asset sub-path to actually detect runtime/native assetType?
natemcmaster commentedon May 12, 2016
If I manually change project.lock.json to assetType native, p/invoke finds sqlite3.dll just fine.
schellap commentedon May 12, 2016
The problem is NuGet treats it as a managed library, even though it is a native binary, because it lives in
libemgarten commentedon May 12, 2016
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
/libfolder worked before when there was a/nativeand/runtimesfolder.If it is the case that package authors need to separate out native vs managed assemblies when adding them under the
/runtimesfolder 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/net40folder. 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.ericstj commentedon May 13, 2016
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.natemcmaster commentedon May 13, 2016
Thanks @ericstj