简体   繁体   中英

How to access a Visual Studio DTE Addin assembly

Here is what I'm trying to do:

  1. Create an executable that loads the Visual Studio DTE
  2. Access methods of an Addin that is loaded

Here is my code, as followed loosely from this blog .

[STAThread]
static void Main(string[] args)
{
    EnvDTE80.DTE2 dte;
    object obj = null;
    System.Type t = null;

    MessageFilter.Register();
    // Get the ProgID for DTE 10.0.
    t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0", true);
    obj = System.Activator.CreateInstance(t, true);

    var addin = GetAddInByProgID(dte, "MyAddin");
    if (addin != null)
    {
        addin.Connected = true;
        var connectObj = addin.Object;
        var conObjType = connectObj.GetType();
        var methods = conObjType.GetMethods();  // mscorlib methods
        var asm = conObjType.Assembly;  //  is mscorlib
     }
     ...
}

The problem I'm running into is I can't get access to the Addin's assembly. It appears that conObjType 's assembly is mscorlib - but I want access to Myaddin.dll. Any ideas?

Any 3rd party add-in may not expose any method at all other than those required to implement the add-in interface (OnConnection, etc.). Its methods can be internal (not public) or even can be obfuscated.

If it is your add-in, a better approach would be that the add-in provides commands to perform actions, and given your external DTE instance, you can call DTE.ExecuteCommand("MyAddIn.MyCommand").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM