question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a way to list native assets that a project will load from the app directory (list them in deps.json)

See original GitHub issue

In dotnet/runtime we’re currently enabling a feature for applications to carry their own copy of ICU for globalization purposes instead of using system-wide installed ICU.

In order to make this feature work, we’re using NativeLibrary.TryLoad API which uses some probing using NATIVE_DLL_SEARCH_DIRECTORIES property passed by the host to the runtime. However, this property is populated based of the deps.json file, so if we don’t have any native assets coming from NuGet packages or we want to use a different folder for our custom built native assets, we wont be able to load from there as NATIVE_DLL_SEARCH_DIRECTORIES will not include this directory. This is of course blocking for framework dependent apps as for self contained apps NATIVE_DLL_SEARCH_DIRECTORIES includes the app directory always.

Currently the only way to have native assets included in deps.json file is via NuGet resolved assets, however, I did manage to do this by adding:

  <ItemGroup>
    <IcuAssemblies Include="icu\*.so*" />
    <RuntimeTargetsCopyLocalItems Include="@(IcuAssemblies)" AssetType="native" CopyLocal="true" DestinationSubDirectory="runtimes/linux-x64/native/" DestinationSubPath="%(FileName)%(Extension)" RuntimeIdentifier="linux-x64" NuGetPackageId="System.Private.Runtime.UnicodeData" />
  </ItemGroup>

This requires me to specify a NuGetPackageId and it has to be an actual package that the app references, so if I have a project that doesn’t reference any NuGet packages, then I won’t be able to do this.

Open questions

Should assets specify a RID or should the SDK assume it, based on the publish/build rid? How should they be listed in the deps.json file? Under the built app library section? Under a new loose native assets section? We need to make sure this works end-to-end on publish, packaging and as transitive dependencies as what if I have a reference to an app that depends on this loose native assets?

Notes

This will be a very important feature for ICU story since we’re now providing a default behavior to use ICU on Windows and many customers will want to use the same version or a custom version with custom locales in their app across different OSs.

cc: @dsplaisted @ericstj @jkotas @tarekgh @eerhardt @jeffschwMSFT

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ericstjcommented, Mar 5, 2021

Might be the same issue as https://github.com/dotnet/sdk/issues/10575 Related https://github.com/dotnet/runtime/issues/11404 Seems like it’s needed for https://github.com/dotnet/core/issues/5699 cc @terrajobst

I hacked this together a bit. The SDK does honor items that the project creates but they must be tied to a package. It won’t honor any items that claim to come from the project.

Here’s a very ugly hack: https://github.com/ericstj/sample-code/tree/nativeLibSample I wouldn’t recommend shipping this deps file produced with this method, but it might do the job for local testing.

Not sure if NuGet would need to be involved for transitive references, what if these were just flowed via MSBuild items and you could add them to https://github.com/dotnet/sdk/blob/b91b88aec2684e3d2988df8d838d3aa3c6240a35/src/Tasks/Microsoft.NET.Build.Tasks/SingleProjectInfo.cs#L24?

2reactions
dsplaistedcommented, Apr 28, 2020

Some possible syntaxes (based on a group discussion):

<ItemGroup>
  <NativeLibrary Include="path/to/icu.so" RuntimeIdentifier="linux-x64" />

  <Content Include="path/to/icu.so" CopyToOutput="PreserveNewest"
     RuntimeIdentifier="linux-x64" />
</ItemGroup>

Ideally this would be transitive. That could require plumbing through NuGet.

Also look at how Xamarin represents native assets for iOS and Android.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Deep-dive into .NET Core primitives: deps.json ...
I learned to program with gcc, C++, and vim. When I started working with C# and .NET, clicking the “Start” button in Visual...
Read more >
deps.json and *.runtimeconfig.json files are not copied from ...
The following approach worked. I've created a <NuGet package name>.props file in build folder of the project with the following content:
Read more >
MSBuild reference for .NET SDK projects
The GeneratedAssemblyInfoFile property defines the relative or absolute path of the generated assembly info file. Defaults to a file named [ ...
Read more >
Using packages
Open the pubspec.yaml file located inside the app folder, and add css_colors: under dependencies . Install it. From the terminal: Run flutter pub...
Read more >
Project Configuration
Both package.json and project.json files are located in each project's folder. Nx merges the two files to get each project's configuration. The full...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found