XLL+ Class Library (6.3)

Deploying your .NET assemblies

Calling your own .NET assemblies

You can call your own or 3rd-party .NET assemblies from add-in fuctions or event handlers.

It is a good idea, if possible, to add the C# or VB.NET project to your add-in solution (as we have in the AssemblyDemo sample). This lets you debug both sides at the same time: you can step from the C++ add-in into the .NET assembly and back again, seamlessly.

Referencing a .NET assembly

To call a .NET assembly from your add-in's C++ code, you must add a reference to your project.

  1. Open the Project Settings window.
  2. Select the page "Common Properties/References".
  3. Click "Add New Reference..." (and prepare for a potentially long wait).
  4. If your assembly is part of the current solution, use the "Projects" to select the project and press "OK".
  5. If the assembly is not part of your solution, then use the "Browse" page to navigate to the assembly.

Once the reference is added, a bonus is that Intellisense becomes available in your C++ code, which can save a lot of typing and errors.

Loading .NET assemblies

The XLL+ framework adds an event handler to the current AppDomain so that the add-in can specify the location of the .NET assembly to be loaded.

By default, the add-in looks in its own directory for any .NET assemblies. So, if you deploy your .NET assemblies (and any assemblies upon which they depend) to the same directory as your XLL file, you need not concern yourself any further with the details of assembly loading.

If your assemblies are deployed to a different location, then use CXllApp::SetPrivateBinPath() to set the list of directories that the loader will search. You should call SetPrivateBinPath in the XllOpenEx() event handler, before you call any methods from your assemblies.

CopyC++
BOOL CClrAddinApp::OnXllOpenEx()
{
    ...

    // Set up assembly loading 
    // This will append "C:\Assemblies" to the assembly loader's search path
    SetPrivateBinPath(GetPrivateBinPath() + ";" + "C:\\Assemblies");

    ...
    return TRUE;
}

GAC

If your assemblies have been added to the Global Application Cache (GAC) then you do not need to concern yourself with the private bin path; your assemblies will automatically be loaded at run-time.

.NET runtime

You need to ensure that the machines on which your .NET-dependent add-ins are deployed are properly configured to run .NET add-ins under Excel. Please see the technical note .NET requirements for more information.

Next: Using the Excel object model >>