Excel-DNA / ExcelDna

Excel-DNA - Free and easy .NET for Excel. This repository contains the core Excel-DNA library.
https://excel-dna.net
zlib License
1.26k stars 270 forks source link

Add functionality to pack and retrieve arbitrary files specified in .dna #688

Open rob-oehm-automation opened 3 months ago

rob-oehm-automation commented 3 months ago

Hi @govert

This PR is my attempt to address #331 and adds a File element type to the .dna schema as well as the corresponding code to pack and unpack the files.

By inspection, this code should achieve this, however, I am not sure of the process to generate tests to ensure that this code is working as expected. It looks like the packing tests rely on known-good binary files, what do I need to do to create one of these files with an embedded file?

The main changes are:

CLAassistant commented 3 months ago

CLA assistant check
All committers have signed the CLA.

govert commented 3 months ago

Thank you for the pull request @rob-oehm-automation - I'll have a look.

tomap commented 3 months ago

@rob-oehm-automation I'm interested in understanding your use case. Thank you

rob-oehm-automation commented 2 months ago

I have a need to load some assemblies dynamically but still want the convenience of distribution via a single xll. .NET dlls packed and then re-extracted are not identical files, I guess the packing process does some IL rewriting so a re-extracted file isn't loaded correctly as a .NET Assembly.

govert commented 2 months ago

Hi @rob-oehm-automation - you say

.NET dlls packed and then re-extracted are not identical files

The assemblies should be identical after extraction - the Excel-DNA build does not do any IL rewriting or any other change. The assemblies are packed in compressed format (this can be disabled in the project file) but when loaded should be 100% identical to the built binary.

It would be easier to use the existing assembly packing mechanism (maybe exposing an access helper) than adding support for general file packing.

In the past I've suggested that add-in libraries should pack any additional files as normal resources into the .NET .dll output, keeping the Excel-DNA packing for the special cases where the library load resolution needs to be done by the Excel-DNA loader.

I'm not completely against adding the more general option - it could be more convenient than the built-in .NET resource management mechanism. But it would be a duplication of that functionality in a sense.

rob-oehm-automation commented 2 months ago

There must be some issues with my extraction code then. I will investigate that further.