Package Multiple .NET 6 Projects into a Single Add-In

151 views
Skip to first unread message

Daniel Horrigan

unread,
May 22, 2023, 6:02:44 AM5/22/23
to Excel-DNA
Hi,

I am currently in the process of porting a solution containing 10+ projects from .NET framework 4.5 to .NET 6.

Previously, I have been using ExcelDnaPack.exe to combine each of the projects into a single .xll file to be used as an Excel add-in. I have done this by supplying a custom .dna file to ExcelDnaPack.exe which specifies each of the projects to include in the final .xll file:

<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="MyAddin" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
  <ExternalLibrary Path="Proj1.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" COMServer="true" />
  <ExternalLibrary Path="Proj2.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" COMServer="true" />
  <ExternalLibrary Path="Proj3.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" COMServer="true" />
.
.
.
</DnaLibrary>

However, since updating each of the projects to .NET 6, this approach no longer seems to work for me. When I use the ExcelDnaPack.exe tool with the same .dna file, the resulting .xll add-in throws an error when loaded into Excel (see below for an example of this error).

What is the best way to package multiple Sdk-style (.NET 6) projects into a single add-in? Or is that even supported?

---

Excel error (copied from excel sheet):
This add-in is built with Excel-DNA and is being loaded from the following location:


A problem occurred while attempting to load the .NET runtime:s
This error can occur if the .NET framework is not installed.f
Please ensure that the Microsoft .NET Framework 2.0 or later is installed before loading the add-in.B
This error can occur if the .NET runtime is not installed, if version 2.0 or later is not installed, if the AppPatch registry entries are incorrect, or if there is an excel.exe.config configuration file restricting the versions of the .NET runtime that can be loaded by Excel.˜
Please ensure that the Microsoft .NET Framework Version 2.0 or later is installed, and will be loaded correctly by Excel, before reloading the add-in.P
This is an unexpected error. Please report this error to the add-in developer.ZThe .NET runtime was loaded but could not be started:

This is possible if another managed add-in caused the runtime to load, using the incorrectly installed AppPatch policy.ÊReview the other managed Excel add-ins that are loaded, or ensure that the .NET 2.0 runtime loads by setting an appropriate 'supportedRuntime' entry in a configuration file for Excel (Excel.exe.config).NThe Microsoft .NET Framework 2.0, 3.0 or 3.5 was not detected on this machine.D
Additional error information
wThe required version of the .NET Framework is installed but could not be loaded.
No other version is currently loaded.ýReview the other add-ins that are loaded, or ensure that the .Net 2.0 runtime loads by setting an approriate 'supportedRuntime' entry in a configuration file (Excel.exe.config).
You will need to restart Excel to load the correct version of the runtime.
This is possible if a configuration file or another managed add-in forces an older version of the runtime to load (only one version of the runtime can be loaded into the process).

rA problem occurred while the add-in was creating an isolated application domain and loading required assemblies.
$AppDomainSetup could not be created.!ApplicationBase could not be set. AppDomain could not be created.MThe ASSEMBLY 'EXCELDNA.LOADER' could not be found among the add-in resources.?The ExcelDna.Loader assembly could not be loaded from resource.BThe Name for the ExcelDna.Loader assembly could not be determined.4The type ExcelDna.Loader.XlAddIn could not be found.3The ExcelDna.Loader.XlAddIn.Initialize call failed.{This Excel add-in requires the Microsoft .NET Framework 4.

A problem occurred while attempting to load the .NET runtime:[
Please ensure that the Microsoft .NET Framework 4 is installed before loading the add-in.ª
This problem usually indicates that the Microsoft .NET Framework 4 is not installed on this computer.+

A problem occurred while attempting to load the requested version of the Microsoft .NET runtime:

If no version is specified in the <addin>.dna file, the host will attempt to load .NET version 2.0.
To load version 4, add a RuntimeVersion='v4.0' attribute to the DnaLibrary tag in the <addin>.dna file.3
Please ensure that the correct version of the Microsoft .NET Framework is requested by the add-in and that the required version is installed.ÊThis Excel add-in requires an '<addin>.dna' configuration file which matched the '<addin>.xll' file.

The required '.dna' file could not be loaded from resources, and was not found in the file system:1
Please ensure that the required '.dna' file exists in the same directory as the '.xll' add-in, and has the correct matching filename.ÑThis Excel add-in requires an '<addin>.dna' configuration file which matches the '<addin>.xll' file (or an embedded resource with the '.dna' file contents).

Govert van Drimmelen

unread,
May 22, 2023, 6:38:50 AM5/22/23
to exce...@googlegroups.com

--------------------------------------------------
Excel-DNA is now registered on 
GitHub Sponsors.
Sign up now to encourage further support and development.
--------------------------------------------------

 

Hi Daniel,

 

Multiple ExternalLibrary assemblies should still work if you still have a .dna file in your project.

(For a single ExternalLibrary, one mostly does not need the .dna file anymore and can configure everything in the .csproj file).

When building you should no longer be using the ExcelDnaPack.exe command line tool.

The NuGet package contains a build task the does the packing now.

 

It looks from the error like you have the wrong version of the .xll being used.

I guess this can happen if an old version of ExcelDnaPack is running after the build.

Also, the new packed output would go into a “publish” subdirectory under the build outputs by default.

 

I suggest removing any post-build steps and deleting the output directories, then rebuilding.

If you still get the error, have a look at the build output and if you’re still stuck, write again.

 

-Govert

--
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/3bc7b996-0e6a-4de3-9a1c-0db57637b266n%40googlegroups.com.

Daniel Horrigan

unread,
May 24, 2023, 8:40:56 AM5/24/23
to Excel-DNA
Hi Govert,

Thanks for your reply and for your suggestions.

I've tried doing what you have suggested above, but unfortunately, I'm still not having much success.

I've stopped using the ExcelDnaPack.exe tool to pack the projects, however, now each time I build the project, my custom .dna file containing all of the ExternalLibrary references is overwritten by the auto-generated .dna file for the project I'm using as the build target.

So, for example, if I have Proj1's .dna file laid out like this:

<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="MyAddin" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
  <ExternalLibrary Path="Proj1.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" COMServer="true" />
  <ExternalLibrary Path="Proj2.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" COMServer="true" />
  <ExternalLibrary Path="Proj3.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" COMServer="true" />
.
.
.
</DnaLibrary>

After building, it becomes:

<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="MyAddin" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
  <ExternalLibrary Path="Proj1.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" COMServer="true" />
  <!--
       The RuntimeVersion attribute above allows only the following setting:
       * RuntimeVersion="v4.0" - for .NET 4.5 or higher
.
.
.
</DnaLibrary>

I've tried adding the ExternalLibrary references to each project's .dna file, but this still did not solve my issue.

Previously, I would have used ExcelDnaPack.exe like so to target my specific custom .dna file:

    > ExcelDnaPack.exe My_AddIn.dna /O output_dir\My_AddIn.xll /Y

If you could advise on how/if I can achieve a similar result without using the command line tool, it would be greatly appreciated. 

Thanks!

P.S. I'm using ExcelDna.AddIn version 1.6.0 from NuGet

Govert van Drimmelen

unread,
May 24, 2023, 9:04:08 AM5/24/23
to exce...@googlegroups.com

Hi Daniel,

 

Don’t edit the .dna file in the output directory, but put your .dna file in the add-in project’s main directory directly.

Then this .dna file should be copied (for 32-bit and 64-bit) into the output directory without changes, and the .xll file outputs will be matching names.

With the latest ExcelDna.AddIn NuGet package, the packed output files go into a ‘publish’ subdirectory.

Daniel Horrigan

unread,
May 25, 2023, 10:25:22 AM5/25/23
to Excel-DNA
Hi  Govert,

That's working perfectly now! 

Thanks so much for all of your help!
Reply all
Reply to author
Forward
0 new messages