packed xll with sub-directory references

194 views
Skip to first unread message

Chris G

unread,
Dec 16, 2016, 2:19:57 PM12/16/16
to Excel-DNA
My goal is to use the packed xll but only pack my MyExcelDnaAddIn.dll and have all other reference dlls (NetOffice etc) in a subdirectory of the .dna/.xll directory.  Is this possible? I can't get it to work.

My .dna file attempting to achieve this looks like this:

<DnaLibrary Name="MyAddIn" RuntimeVersion="v4.0">
  <ExternalLibrary Path="lib\MyExcelDnaAddIn.dll" LoadFromBytes="false" ExplicitExports="true" Pack="true" />  
  </DnaLibrary>


The unpacked xll runs fine with all dlls in the lib subdirectory. However, using my packed xll, and if I delete the MyAddIn.dll from the lib subdirectory, then the AddIn doesn't load.  In other words, the packing didn't really work because the xll file was looking for the dll and couldn't find it.

I can get packing to work fine, so long as there are no subdirectories involved- ie. if everything is in one folder.  However, I really want to have a lib folder to house the third-party dlls and have MyExcelDnaAddIn.dll inside the xll so users never see it.


Appreciate any help you can provide.

Chris

Govert van Drimmelen

unread,
Dec 18, 2016, 4:47:22 AM12/18/16
to exce...@googlegroups.com
Hi Chris,

These are issues relating to the .NET runtime more than Excel-DNA specifically.


.NET won't automatically look for assemblies in a subdirectory, so you have to do some extra work to have them found. One tricky aspect is that your setup for this must happen before Excel tries (and fails) to load those dependencies.

You can experiment with SetPrivateBinPath, or handle the AssemblyResolve event yourself.

You must also decide whether these complications make it worth having the libraries in a separate directory. In my experience, it is not.

-Govert



From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of Chris G [chris...@gmail.com]
Sent: 16 December 2016 09:19 PM
To: Excel-DNA
Subject: [ExcelDna] packed xll with sub-directory references

--
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 post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.

Chris G

unread,
Dec 19, 2016, 10:52:31 AM12/19/16
to Excel-DNA
Thanks, Govert.  I've decided it isn't worth it, like you say.  I will use the packed-xll so I can even do away with the .dna file, which I quite like.  I've also dropped using NetOffce and am using PIAs, so the packed file is quite small.
To post to this group, send email to exc...@googlegroups.com.

Lubos

unread,
Jan 31, 2017, 3:46:23 PM1/31/17
to Excel-DNA
Hello,

I am confused about this topic. Does that mean that the first solution described in the answer here is not going to work?

What I tried is this in my starter addin dna:

<DnaLibrary Name="Lubo.MyApp.Starter Add-In" RuntimeVersion="v4.0">
  <ExternalLibrary Path="Lubo.MyApp.Starter.dll" LoadFromBytes="true"/>  
  <ExternalLibrary Path="v1.0.0.0\Lubo.MyApp.Bootstrapper-AddIn.dna"/>
</DnaLibrary>

and in the bootstrapper:

<DnaLibrary Name="Lubo.MyApp.Bootstrapper Add-In" RuntimeVersion="v4.0">
  <ExternalLibrary Path="Lubo.MyApp.Bootstrapper.dll"/>
  <ExternalLibrary Path="Lubo.MyLibs.Excel.Functions.dll"/>
  <Reference Path="Lubo.MyLibs.Common.dll"/>
  <Reference Path="Lubo.MyLibs.Excel.dll"/>
</DnaLibrary>

My aim was to have the starter project completely empty so that it doesn't change. Ribbon class inheriting from ExcelRibbon is in bootstrapper. But that doesnt seem to work or I made it wrong.


Thanks

Lubos



Dne neděle 18. prosince 2016 10:47:22 UTC+1 Govert van Drimmelen napsal(a):
To post to this group, send email to exc...@googlegroups.com.

Govert van Drimmelen

unread,
Jan 31, 2017, 4:19:47 PM1/31/17
to exce...@googlegroups.com
Hi Lubos,

The nested .dna files and ExternalLibrary parts should work right.

But the two Lubo.* references in the subdirectory won't be resolved. Excel-DNA doesn't use the Reference tags for assembly resolution at runtime (maybe it should). They're only used for dynamically compiled code and for packing at build-time.

-Govert
To post to this group, send email to exce...@googlegroups.com.

Lubos

unread,
Feb 1, 2017, 6:40:32 AM2/1/17
to Excel-DNA
Hello Govert,

thank you for your response. I am coming from VBA, no pro programmer and this is all new to me. Is there any comprehensive source about how this works?


So Refernece tag is not needed in this situation because I am not packing. Right now my solution looks like this:

Addin\Lubo.MyApp.Starter.dll
Addin\Lubo.MyApp.Starter-AddIn.dna
Addin\Lubo.MyApp.Starter-AddIn.xll

subfolder:
Addin\v1\Lubo.MyApp.Bootstrapper.dll
Addin\v1\Lubo.MyApp.Bootstrapper-AddIn.dna
Addin\v1\Lubo.MyApp.Bootstrapper-AddIn.xll
Addin\v1\Lubo.MyLibs.Common.dll
Addin\v1\Lubo.MyLibs.Excel.dll
Addin\v1\Lubo.MyLibs.Excel.Ribbon.dll
+ all other dlls referenced and used in Bootstrapper.dll


Starter dna content:


<DnaLibrary Name="Lubo.MyApp.Starter Add-In" RuntimeVersion="v4.0">
  <ExternalLibrary Path="Lubo.MyApp.Starter.dll" LoadFromBytes="true"/>
  <ExternalLibrary Path="v1\Lubo.MyApp.Bootstrapper-AddIn.dna" LoadFromBytes ="true"/>
</DnaLibrary>

Bootstrapper dna content:


<DnaLibrary Name="Lubo.MyApp.Bootstrapper Add-In" RuntimeVersion="v4.0">
  <ExternalLibrary Path="Lubo.MyApp.Bootstrapper.dll" LoadFromBytes="true"/>
  <ExternalLibrary Path="Lubo.MyLibs.Excel.Functions.dll" ExplicitExports="true" />       ... this is where my functions live
</DnaLibrary>

When I run Boostrapper Addin.xll directly everything is fine. But when I try starter version the bootstrapper is called but ribbon construction is not.

I have ribbon class in bootstrapper project like this:

[ComVisible(true)]
public class MyRibbon : ExcelRibbon
{
 public override string GetCustomUI(string RibbonID){...}
...
}

Is there a way to make this work or am I completely off?

Thank You.


Lubos



Dne úterý 31. ledna 2017 22:19:47 UTC+1 Govert van Drimmelen napsal(a):

Govert van Drimmelen

unread,
Feb 1, 2017, 8:44:15 AM2/1/17
to exce...@googlegroups.com

Hi Lubos,

 

First you should check that it works when you load Addin\v1\Lubo.MyApp.Bootstrapper-AddIn.xll directly.

 

Once that works, you can try to make your Starter add-in that in turn loads the Bootstrapper. You won’t be able to load the Bootstrapper just from the .dna file. Instead, in the Lubo.MyApp.Starter.dll code you put some code that loads it with a call to Application.RegisterXLL(pathToBootstrapper…)

 

-Govert

Lubos

unread,
Feb 1, 2017, 3:05:04 PM2/1/17
to Excel-DNA
Hi Govert,

everything is working now. I followed your instruction, tested bootstrapper itself - ok.Then I added RegisterXLL to the Starter AutoOpen. Problem was file path in the code. It would destroy original intent so I loaded the path from text file. Then I experimented a bit and found out, that the line  <ExternalLibrary Path="v1\Lubo.MyApp.Bootstrapper-AddIn.dna" LoadFromBytes ="true"/> in Addin\Lubo.MyApp.Starter-AddIn.dna is not needed. Or it seems. So I exluded it and packed both starter and bootstrapper.


Thank you for help.

Lubos

Dne středa 1. února 2017 14:44:15 UTC+1 Govert van Drimmelen napsal(a):
Reply all
Reply to author
Forward
0 new messages