Udostępnij za pośrednictwem


Considerations for Loading Add-Ins

The way that an application discovers and loads add-ins depends on many factors, such as which set of features you want to expose to add-ins and how you want your application to load add-ins. Before you write code to discover and load add-ins, you must consider the following design decisions.

Determining When Add-ins Will Be Loaded and Unloaded

You must define when your application loads and unloads add-ins. Knowing when add-ins will be loaded helps you determine where in your application to call into the methods for discovering and loading add-ins. Visual Studio Tools for Applications supports loading and unloading add-ins at any point during the lifetime of the application.

An application that supports application-level add-ins might load all available add-ins when the application starts, or it might enable end users to load add-ins at run time—for example, by clicking a menu command. An application that supports add-ins might unload all loaded add-ins when the application exits, or it might enable end users to manually unload add-ins while leaving the application open.

Determining Where to Search for Add-Ins

Visual Studio Tools for Applications can load add-in assemblies only from a hard disk location. If your host application stores an add-in assembly in another storage format, such as a database, you must copy the add-in assembly to a hard disk location before loading the add-in.

There are two main deployment models:

  • Directory-based deployment. In this model, the host application discovers add-ins by searching in one or more directories that are known to the host application. You can use the API provided by the .NET Framework to discover and load add-ins that use this deployment model. For more information, see Discovering and Loading Add-Ins.

  • ClickOnce deployment. If the host application implements a ClickOnce deployment model for add-ins, you must use one of the extension methods provided by Visual Studio Tools for Applications to discover and load add-ins. For more information, see Deploying Add-ins by Using ClickOnce.

For more information about these deployment models, see Securing and Deploying Add-Ins.

Integrating the Code That Discovers and Loads Add-ins With the Host Application

How you implement the code that discovers and loads add-ins is entirely up to you. However, the architecture of your application might impose some restrictions.

The API for discovering and loading add-ins is a managed API. Therefore, to use this API in an application that is written using unmanaged code, you must use the API in a separate managed assembly that communicates with the unmanaged host application by using COM interop.

If your application is written using managed code, you can write the code in a separate assembly that is referenced in your application, or you can add the code directly to the code base of your application.

For a walkthrough that demonstrates how to modify an application so that it discovers and loads add-ins, see Walkthrough: Modifying an Application to Load Add-Ins.

See Also

Tasks

Walkthrough: Modifying an Application to Load Add-Ins

Concepts

Discovering and Loading Add-Ins

Implementing Host Services

Understanding the Add-in Pipeline in Visual Studio Tools for Applications

Preventing Unexpected Application Failures from Partially Trusted Add-Ins