layout | title |
---|---|
page |
Excel-DNA Reference: .dna file |
Elements and attributes are below. See *.dna files in downloaded samples.
-
DnaLibrary
Name
Description
Language
RuntimeVersion
eitherv4.0
for .NET 4, orv2.0
(default) for all earlier versions. i.e. usev2.0
for .Net 3.5. Note thatv4.0
is required for 64bit Office.CompilerVersion
ShadowCopyFiles="true"
enables shadow copying for the add-in's AppDomain.
-
ExternalLibrary
Path
Pack
LoadFromBytes
. if ="true" then the .dll is loaded more dynamically which can avoid needing to shut down Excel during debugging. However, it can cause issues with multiple active instances and harder debugging.ExplicitExports="true"
Prevents every static public function from becomming a UDF, they will need an explicit[ExcelFunction]
annotation.
-
Project
SourceItem
-
Image
-
CustomUI
Nest<customUI
under this to define ribbon.
(Attributes set on the DnaLibrary
apply to the implicit project and are not inherited by any <Project>
sections.)
ExcelDnaPack
can pack the .dna files and dependent assemblies into a single .xll file.
The Samples\Packing
directory has a number of samples of how to use the packing feature.
To run the samples, run PackAll.bat - the packed libraries are placed into the out directory.
A reference to the ExcelDna.Integration assembly in the .xll file that is loading a .dna file is always added when the .dna file is compiled.
In addition, the following references are added to each project, unless a DefaultReferences="false"
attribute is set on the :
System.dll
System.Data.dll
System.Xml.dll
For RuntimeVersion="v4.0" the following are added too:
System.Core.dll
System.Data.DataExtensions.dll
System.Xml.Linq.dll
Microsoft.CSharp.dll
(C# projects only)
For VB projects, the following imports are added, unless a DefaultImports="false"
attribute is set on the <Project>
:
Microsoft.VisualBasic
System
System.Collections
System.Collections.Generic
System.Data
System.Diagnostics
ExcelDna.Integration
For RuntimeVersion="v4.0"
the following are added too:
System.Linq
System.Xml.Linq
?? Microsoft.Office.Core
(for Ribbon)??
Image is only used if the Path is supplied.
Image Name must match (case sensitive) the image tag in the Ribbon markup.
- If the Path starts with
packed:
the image is retrieved from resources. - If the Path contains .....
The <Reference>
element has Path (AssemblyPath
is deprecated) and Name
attributes.
When compiling at runtime, the references are resolved as follows:
- If Path starts with "packed:" the assembly is retrieved from resources, written to a temp file, and the temp file is added to the compiler's references list.
- Else If Path is not null and not empty, the assembly is search relative to the .dna file and the xll directory, and in the framework directory. If found, Path is added to the compiler's references list.
- Else the Name is passed to LoadWithPartialName for resolution.
- Otherwise the reference is ignored.
When packing (Reference elements with the Pack="true" attribute), the reference is resolved as follows:
- If Path starts with "packed:" the reference is ignored.
- If Path is not null and not empty, the assemlby is looked for according to the Path Resolution rules.
- If no file is found, Assembly.Load is attempted with the Path. If the load succeeeds, the assembly location is used to locate and pack the assembly.
- Otherwise, Assembly.LoadWithPartialName with Name is tried. If the load succeeeds, the assembly location is used to locate and pack the assembly.
- If the assembly is still not located, the reference is ignored for packing.
For assemblies and .dna files, the following path resolution is done. Given a path containing a file name, maybe rooted, maybe wi th some or no directory info, we attempt to find the file as follows:
- If the file is found at the path, we are done.
- Check the path - if it is rooted replace directory with .dna file's directory.
- If the path is not rooted, try the whole path relative to the .dna file location (prepend the .dna file's directory).
- Else try 2 or 3 using current AppDomain's BaseDirectory.
If the ExplicitExports
attribute is set to true
on a Project
or ExternalLibrary
node, only functions and methods explicitly marked by an
ExcelFunction
or ExcelCommand
attribute are exported. Otherwise, all public static methods with compatible signatures are exported.
Cleanup is only done when the add-in is removed from the add-in manager.
When File->Open
is used to reopen the .xll, it is closed and opened, causing the .dna file to be re-read.