Search code examples
vstoms-officeoffice-interop

How to manage resources in a VSTO Office Addin


I'm creating my first VSTO plugin for Microsoft Project and I'm trying to figure out how to handle global resources.

I have a library that manages and provides data from a webservice that I want to use to create Tasks in MS Project. However, I'm trying to figure out where to put that singleton of this library. It seems too-easy to put into my RibbonBase class, but I cant figure out a way to use the ThisAddIn class to manage/keep connections.

What is the expected way to manage tabs/buttons, and the resources they need?


Solution

  • RibbonBase is for ribbon callbacks mostly. I'd recommend keeping the business logic outside of this class. Note, you can access an instance of the add-in class by using the Globals.ThisAddIn property.

    Globals is a static class that keeps references to certain items in your project. By using the Globals class, you can access the following items from any code in the project at run time:

    • The ThisAddIn class in an VSTO Add-in project. You can access this object by using the Globals.ThisAddIn property.
    • All Ribbons in your project that you customized by using the Ribbon Designer. You can access the Ribbons by using the Globals.Ribbons property.

    For more information, see Accessing the Ribbon at Run Time.

    You can read more about the Fluent UI (aka Ribbon UI) in the following series of articles: