-
Notifications
You must be signed in to change notification settings - Fork 10
Referencing external assemblies
This article answers a question – how to make the plug-in work, when it depends on the external assemblies.
It is rather rare case when the plug-in is almost self-contained and references only .NET Framework assemblies. More common case is when the plug-in uses various frameworks to perform specific tasks. These frameworks usually come as C# assemblies (.dll files) via NuGet packages. Also the dependency may be a project in the same VS solution or just an external standalone .dll file.
There are 4 ways you can make your plug-in work, when it depends on external assemblies:
- Use Costura.Fody to merge all dependencies into the plug-in assembly and distribute the plug-in as all-in-one assembly. This is the recommended solution because it is simple and just works. Also it is the most convenient way of distributing the plug-in since it contains of a single .dll file, which user must copy.
- Copy the dependencies to the application domain base directory. Usually it's PL/SQL Developer home directory.
- Load dependencies into the .NET global assembly cache (GAC). This topic is not explained here.
- Use reflection. This is the most inconvenient way of calling the dependencies.
DISCLAIMER
There are several solutions for merging C# assemblies (Costura.Fody, ILMerge, ILRepack etc). Only some of them were tested.
This article does not state, that some of them are good and the others are bad. While those solutions may work in other scenarios, and one may choose the solution that works for him/her, this article describes the solution, which works in the PL/SQL Developer context e.g. does not conflict with UnmanagedExports.Repack and makes resulting assembly be recognizable by the PL/SQL Developer as a plug-in.
Merging the assemblies:
- Install Costura.Fody NuGet package.
- Build the project.
First time in the output you'll get a warning, thatFodyWeavers.xmlis not found in the project root directory and the default one has been generated.
Add that file to your project: in VS right-click your project, Add... > Existing Item..., choose FodyWeavers.xml. - Done.
This article provides very short intro on Costura.Fody usage, which is actually enough for building PL/SQL Developer plug-in.
DemoAssemblyMerge project demonstrates the concept.
Just copy/paste dependencies (their .dll files) to the PL/SQL Developer home direcotry. More precisely, the base directory of the application domain AppDomain.CurrentDomain.BaseDirectory. Plug-in must be located in the plg-ins directory. The file layout must look like:
PL/SQL Developer home/
dependency1.dll
dependency2.dll
...
PlugIns/
plugin.dll
Introduction
Main concepts
- Anatomy of the plug-in
- Exporting DLL functions
- Using callbacks
Misc
- Using menu items
- Accepting commands in the command window
- Validating DLL exports
- Working with color preferences
- Referencing external C# assemblies