Add Support for Embedding Unmanaged Assemblies using Costura.Fody
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 7.8k
- Forks
- 1.2k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 49
Description
Add Support for Embedding Unmanaged Assemblies using Costura.Fody
Is your feature request related to a problem? Please describe.
The Costura.Fody project makes it possible to embed unmanaged assemblies into C# DLLs/executables, resulting in a cleaner output directory with fewer files.
However, Stride currently lacks support for Costura.Fody's unmanaged resource embedding, likely due to issues related to the NativeLibraryHelper. This component is responsible for pre-loading assemblies, and when assemblies are embedded they are not present on disk, which leads to a FileNotFoundException.
Describe the solution you'd like
Stride could embed it's assemblies within itself with the use of Costura.Fody, and if the developer wants a single file, all they would have to do is add the PublishSingleFile property, as Stride is a managed assembly I expect it would embed just fine, even if it had unmanaged assemblies within it.
I prefer this to the alternative solution as it offloads the responsibility of tracking which assemblies need to be embedded for all the different platforms (win-x64, win-x86, win-arm, linux, mac, ...) to the engine, making it less effort for the developer to setup and maintain.
Describe alternatives you've considered
Add Option for Disabling Pre-loading of Assemblies: Stride could introduce an option that allows developers to disable the pre-loading of assemblies. This way, the exception caused by embedded assemblies not being found on disk would not occur, and developers could successfully embed these assemblies within the executable.
Additional context
I have created a project that demonstrates the current state of incompatibility with Stride embedding unmanaged assemblies using Costura.Fody:
https://github.com/kdserra/EmbeddingTest
The way I find the native libraries that need to be included is:
I set the runtime identifier to the target platform in the csproj, publish for it, copy and libraries into native-lib folder and embed as resource, and add it to FodyWeavers.xml.
This is why the preferred solution is better, as it offloads this responsibility to the engine.
Note:
Embedding Managed assemblies are already supported without the need for Costura.Fody via <SelfContained> and <PublishSinglefile> properties, so this would be the final step to embedding the remaining unmanaged assemblies.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with sources/core/Stride.Core/Native/NativeLibraryHelper.cs and reproduce the failure using the linked EmbeddingTest project, Costura.Fody, and its FodyWeavers.xml setup. Compare the managed single-file properties in the project files with the unmanaged embedding case. Done means a supported approach embeds the required unmanaged assemblies across the stated target platforms without a FileNotFoundException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100