none
calling constructor of VSTO Addin (thisaddin class) from a C# application RRS feed

  • Question

  • I have a VSTO addin which I want to invoke from a C# EXE. thisaddin.designer.cs file has a constructor as below.
    Collapse | Copy Code
    public ThisAddIn(global::Microsoft.Office.Tools.Word.ApplicationFactory factory, global::System.IServiceProvider serviceProvider) : 
                    base(factory, serviceProvider, "AddIn", "ThisAddIn") {
                Globals.Factory = factory;
            }
     
    I have added the reference of Addin to my C# project and tried the below. But, not sure what arguments to pass.
    Collapse | Copy Code
    MTMWordAddIn.ThisAddIn addin = new MTMWordAddIn.ThisAddIn(null, null);
     
    Kindly suggest.
    Thanks.
    Wednesday, March 12, 2014 8:19 PM

Answers

  • Why do you need to create an instance of the add-in class?

    Note, the add-in class is not designed to be created by other applications. Instead, it should created and called by the VSTO runtime.

    Wednesday, March 12, 2014 8:51 PM
  • Hi,

    As Eugene said, I'm afraid you cannot use your EXE to launch the VSTO dll directly.

    In fact, VSTO is used to develop Office add-ins or templates which could be deployed into the Office applications. This is different from creating a project to be built as a dll file. To run a VSTO add-in, the Visual Studio Tools for Office Runtime must be installed. The runtime is installed automatically when you install Visual Studio, Microsoft Office 2013 or Office 2010. After develop a VSTO add-in, if you want to run it on other machines, you need to deploy it. So you could not include the dll of a VSTO add-in into an EXE to run it successfully.

    If you just want to use the features of a Microsoft Office application, I suggest you creating a project and using Office Primary Interop Assemblies(PIA) in it rather than creating a VSTO add-in. The PIA enables managed code to interact with a Microsoft Office application's COM-based object model. In this way, the project could be built as a dll to be used in your EXE.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 14, 2014 2:50 AM
    Moderator

All replies

  • Why do you need to create an instance of the add-in class?

    Note, the add-in class is not designed to be created by other applications. Instead, it should created and called by the VSTO runtime.

    Wednesday, March 12, 2014 8:51 PM
  • I want to create 3 seperate VSTO DLL's for different word versions (2007, 2010 & 2013). Use my EXE to invoke these DLL's after a Word version check on the client system. I don't want to deploy the VSTO Addin as Setup.exe. Rather I want to use my EXE to launch the VSTO dll's. Please suggest.

    Is there any other way?

    Wednesday, March 12, 2014 8:53 PM
  • Hi,

    As Eugene said, I'm afraid you cannot use your EXE to launch the VSTO dll directly.

    In fact, VSTO is used to develop Office add-ins or templates which could be deployed into the Office applications. This is different from creating a project to be built as a dll file. To run a VSTO add-in, the Visual Studio Tools for Office Runtime must be installed. The runtime is installed automatically when you install Visual Studio, Microsoft Office 2013 or Office 2010. After develop a VSTO add-in, if you want to run it on other machines, you need to deploy it. So you could not include the dll of a VSTO add-in into an EXE to run it successfully.

    If you just want to use the features of a Microsoft Office application, I suggest you creating a project and using Office Primary Interop Assemblies(PIA) in it rather than creating a VSTO add-in. The PIA enables managed code to interact with a Microsoft Office application's COM-based object model. In this way, the project could be built as a dll to be used in your EXE.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 14, 2014 2:50 AM
    Moderator
  • Thanks a lot for your reply Luna.

    We have our application built using PIA. We thought of doing the same using VSTO as it is much easier. As you said, I don't see any possibility of launching VSTO dll from an EXE. We'll continue using the old model which suits our architecture.

    Friday, March 14, 2014 5:55 PM