Welcome to MSDN Blogs Sign in | Join | Help

Andrew Whitechapel

Visual Studio, Office and other Nonsense
Demand-Loading VSTO Add-ins

In an earlier post, I talked about how you could delay (or prevent) the loading of managed code using a native add-in. In that post I also listed the standard LoadBehavior settings, and I was assuming that everyone knows how these apply, but I got a couple of follow-up questions that prompted me to clarify the normal (LoadBehavior-based) demand-loading mechanism, and how it applies to VSTO add-ins.

It’s pretty simple: you can set up any Office COM add-in (native, managed, VSTO) for demand-loading in a standard way, that is by setting the LoadBehavior in the registry to 0x10 (16 dec). For versions of Office prior to 2007 (and for those Office apps that don’t yet support the Ribbon), the typical pattern is to create some custom CommandBar control in your add-in at startup. Office will load the add-in the first time it boots after the add-in is registered, call your add-in code to set up the custom UI, and cache this information so that when the user clicks the control, this will load the add-in.

In the case of add-ins that implement custom Ribbons, the behavior is essentially the same: Office will load the add-in the first time it boots after the add-in is registered, call GetCustomUI and cache the ribbon XML. Then, Office resets the LoadBehavior value to 8. Subsequently, when the user clicks one of the ribbon controls, this will load the add-in and set LoadBehavior to 9. This works with both a low-level IRibbonExtensibility implementation and with the VSTO designer-generated ribbon wrappers.

If you want to set LoadBehavior in your project for testing during development, you could create a regedit script, eg:

Windows Registry Editor Version 5.00

 

[HKEY_CURRENT_USER\Software\Microsoft\Office\Excel\Addins\MyAddIn]

"Description"="MyAddIn"

"FriendlyName"="MyAddIn"

"LoadBehavior"=dword:00000010

"Manifest"="c:\\Temp\\MyAddIn\\bin\\Debug\\MyAddIn.vsto|vstolocal"

 

...and then add this to the project properties as a post-build step:

regedit /s "$(SolutionDir)$(SolutionName).reg"

When it comes time to deploy the solution, if you’re using a setup project, you’ll have to set the LoadBehavior by setting the value in the registry editor in your setup project.

 

If you’re using ClickOnce publishing, you’ll need to edit the loadBehavior attribute value manually in the application manifest (and then re-sign the manifest).

 

That’s it. There’s nothing else you need to do. You create your custom Ribbon either using a low-level implementation or using the VSTO designer wrappers – all in the normal way.

Posted: Monday, July 14, 2008 8:24 PM by andreww

Comments

wordyone said:

Thank you for this very informative article as well as the follow-up article. Could you please tell me where the ribbon is cached and how to reset this cache once it has been established?

I have found that once the add-in's ribbon has been cached, if something later changes -- such as the default label or text in a combobox (populated using getText or getLabel callback) -- the "bad" ribbon values persist. I would like to reset the cache somehow because resetting load behavior of my add-in to 16 again does not seem to overwrite the original ribbon that was cached.

# June 25, 2009 3:17 PM

andreww said:

wordyone - to delete Ribbon/CommandBar custom icons, you can simply delete the toolbar cache files. You should take a backup of these files first, and note that these will delete other custom settings (for example, Word's normal.dot contains style customizations etc in addition to Ribbon/CommandBar icons).

Excel: C:\Documents and Settings\<user>\Application Data\Microsoft\Excel\Excel12.xlb (or Excel11.xlb)

Word: C:\Documents and Settings\<user>\Application Data\Microsoft\Templates\Normal.dot(m)

Outlook: C:\Documents and Settings\<user>\Application Data\Microsoft\Outlook\outcmd.dat

PowerPoint: C:\Documents and Settings\<user>\Application Data\Microsoft\Powerpoint\ppt.pcb

# June 25, 2009 4:00 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Page view tracker