In essence, VSTO supports Outlook by providing two things:
- An integrated Visual Studio experience that allows Outlook add-ins to be easily developed and debugged.
- A dedicated loader that is responsible for securely loading and initializing the managed code add-in.
The Visual Studio project system now allows you to create a dedicated Outlook add-in project directly in either C# or Visual Basic .NET. To create a project, just go to File/New/Project/Office/Outlook Add-in. When the project is created you immediately get a reference to the root Outlook application object with startup and shutdown methods via the ThisApplication class. From this class you can access the entire Outlook object model. VSTO Outlook add-ins provide a simpler interface than IDTExtensibility2 so very often you'll really only need to write code into the Startup and Shutdown event handlers. The mandatory Hello World add-in looks like this:
publicpartial class ThisApplication
private void ThisApplication_Startup( object sender, System.EventArgs e )
MessageBox.Show( "Hello World!" );
private void ThisApplication_Shutdown( object sender, System.EventArgs e )
MessageBox.Show( "Goodbye World!" );
Debugging the add-in is easy too – just press F5 and Outlook will start and automatically load your add-in. The project system also creates a convenient setup project so that you can easily install your newly crafted add-in on another user’s machine.
The loader, on the other hand, provides a consistent, robust and secure mechanism for deploying and loading managed code add-ins into Outlook. The loader provides the following benefits:
- No More Shims – The loader removes the need to rely on mscoree or a complex custom COM shim to provide the interface between a managed code add-in and Outlook.
- AppDomain Isolation – Each add-in is loaded into its own AppDomain to increase robustness. The add-in AppDomain is completely unloaded when the add-in is disconnected.
- Code Access Security – The loader uses CAS to ensure that the add-in is appropriately trusted, allowing a finer degree of control than traditional Outlook add-ins.
- Seamless Shutdown – The loader fixes a number of known issues with Outlook add-ins where the add-in is not unloaded properly leading to problems shutting down Outlook cleanly.
- Server Deployment – The loader provides a Click-Once like mechanism to allow an add-in to be deployed to a server so that client machines can be updated automatically. Note that this support will be available in a subsequent release.
Andrew Whitechapel has written an excellent article that describes in some detail the add-in loader architecture and the benefits it provides.