[unpacked approach] Can *.dna file be placed in different location than *.xll file

47 views
Skip to first unread message

Wojciech Mioduszewski

unread,
Oct 27, 2021, 5:04:02 AM10/27/21
to Excel-DNA
Hello!

I decided to use the unpacked approach of distributing Excel Addins through DNA - due to the necessity of being able to update xll/libraries from time to time 
(thanks Govert for the great suggestion - I learned this approach from one of the threads here)

However, I do like to have a relatively clean /%appdata%/Microsoft/Addins directory. I already managed to throw out the dlls that my project produces and here's how it looks like:

%appdata%/Microsoft/Addins
- MyAddin.xll (unpacked)
- MyAddin.dna

%appdata%/MyAddin
- MyAddin.dll
- other dlls

and sample definition of library in my dna:
<ExternalLibrary Path="..\..\MyAddin\Newtonsoft.Json.dll" LoadFromBytes="true" Pack="true" ExplicitExports="true" ExplicitRegistration="true"/>

And here is my question. I would like to limit the content of %appdata%/Microsoft/Addins to just one *.xll file and move *.dna to MyAddin folder.

Is it possible? Can I somehow tell my xll that it needs to look up for dna file somewhere else than the xll file lays?

Cheers!

Govert van Drimmelen

unread,
Oct 27, 2021, 5:38:05 AM10/27/21
to Excel-DNA
--------------------------------------------------
Excel-DNA is now registered on GitHub Sponsors.
You can add Excel-DNA support with easy billing through a corporate GitHub account.
--------------------------------------------------

* The .dna file must either be next to the .xll with the same name, or it must be packed inside the .xll file.

* The .dna file can be packed inside the .xll file with nothing else being packed (if you have not ExternalLibrary or Reference with Pack="true", that's what you'll get - check the output from the ExcelDnaPack run when you build).

* The .dna file can refer to another .dna file which will be relative to the location of the .xll file. So you can have this in your "main" .dna file:
    <ExternalLibrary Path="..\..\MyAddIn\TheRealDnaFile.dna" />
Then put the rest in the external .dna file.

-Govert 

Wojciech Mioduszewski

unread,
Oct 27, 2021, 7:59:11 AM10/27/21
to Excel-DNA
Wow, it works, thank you!

I did it just as you suggested: by packing the main dna file and linking the 'outside' one from it.

The only downside I noticed is that I need to recreate the outside dna in the file system relatively to bin\Debug (or bin\Release) directory.
Given I want to eventually have such tree:

%appdata%/
|---------Microsoft
|---------|---------Addins
|---------|---------|---------PackedAddin.xll
|---------MyAddin
|---------|---------Studio
|---------|---------|---------lib
|---------|---------|---------|---------Newtonsoft.dll
|---------|---------outside.dna

My dna files looks like below:
packed.dna:
<ExternalLibrary Path="..\..\MyAddin\Studio\outside.dna"/>

outside.dna:
<ExternalLibrary Path="lib\Newtonsoft.Json.dll" />

but during the build, the DnaPackageTool is trying to localize the '..\..\MyAddin\Studio\outside.dna' from \bin\Debug context - so I need to create this file precisely in this context, which brings the necessity of moving it back and forth in case of modifying the target path. Do you have any suggestions on how could I improve this process? Or is that's really the only way I can do this?

I was searching through your repo for 'RunExcelDnaPack' customization ability but didn't find anything.
https://github.com/Excel-DNA/ExcelDna/search?q=RunExcelDnaPack

Thank you very much!
Wojciech

C. Augusto Proiete

unread,
Oct 27, 2021, 9:23:59 PM10/27/21
to exce...@googlegroups.com
Cześć Wojciech, another way of doing this is by storing all the files of your addin into any folder you want, and then creating a shortcut (.lnk) to the .xll file.

%appdata%/Microsoft/Addins
- MyAddin.xll.lnk

%appdata%/MyAddin

- MyAddin.xll (unpacked)
- MyAddin.dna
- MyAddin.dll
- other dlls

Excel is smart enough to follow the shortcut and load the addin normally. It also preserves the security properties of the folder where the shortcut is located.

Cheers,
~Augusto




--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/444c6b25-8432-45b3-82a4-f7e141a204b8n%40googlegroups.com.

Wojciech Mioduszewski

unread,
Nov 3, 2021, 12:28:40 PM11/3/21
to Excel-DNA
This works wonderful! Thank you!
Reply all
Reply to author
Forward
0 new messages