VSTO: Understanding
Document-Level Customizations Architecture
Introduction
Document-Level customizations refer to providing managed
extensions to a particular document. E.g. a Word or Excel document. These
customizations do not have any impact on other documents or Office Application
as a whole.
A document level customization in form of a managed assembly
gets attached to the document. Whenever that document is opened, the
customization is loaded and ready to respond to events.
The reference between the document and customization is
established by adding a custom property to the document called
_AssemblyLocation. This property stores the location of Deployment Manifest.
The main design considerations of Office Document-Level
Customization Architecture are following:
·
Each customization is loaded in new application domain so as to
isolate it from main app and other customization. Thus if the customization
hangs whole app doesn’t crashes.
·
Security and Permission level checks performed on customizations.
·
Clean shutdown of application and loaded customizations
While the scope of Application-Level Add-ins is whole
application, the Document-Level customizations have been designed to work with
a single document. A single app domain is created and cross document
communication is not allowed.
Architecture Components
Runtime Loader
The component is named VSTOEE.dll and is responsible
for loading the correct version of VSTO runtime when a document-level
customization is opened or add-in is started.
Solution Loader
It is named VSTOLoader.dll. This is responsible for
loading the VSTO application. It also creates a new Application Domain for each
add-in/customization and performs security checks on VSTO application.
Deployment Manifest and
Application Manifest
The Deployment manifest contains details about the
customization artifacts. Each deployment manifest points to the correct version
of an application manifest which in turn points to assembly paths and entry
points.
Customization Loading Process
1. Office
application checks the custom document properties to see whether there are
managed code extensions associated with the document.
2. It
loads Runtime Loader which in turn loads Solution Loader.
3. Solution
Loader loads the .NET Runtime and managed portion of VSTO Runtime.
4. Latest
versions of Deployment and Application manifests are downloaded. Once security
checks are passed, latest customization assemblies are downloaded.
5. The
Visual Studio Tools for Office runtime creates a new application domain and
loads customization assembly into the application domain.
6. The
Visual Studio Tools for Office runtime calls the Startup event handler in
customization assembly.