簡體   English   中英

如何訪問Visual Studio DTE外接程序程序集

[英]How to access a Visual Studio DTE Addin assembly

這是我想要做的:

  1. 創建一個加載Visual Studio DTE的可執行文件
  2. 加載的外接程序的訪問方法

這是我的代碼, 此博客對此進行了大致介紹。

[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
     }
     ...
}

我遇到的問題是我無法訪問Addin的程序集。 看來conObjType的程序集是mscorlib-但我想訪問Myaddin.dll。 有任何想法嗎?

除了實現外接程序接口(OnConnection等)所需的方法外,任何第三方插件都不能公開任何方法。 它的方法可以是內部的(不公開),甚至可以被混淆。

如果它是您的外接程序,則更好的方法是該外接程序提供執行操作的命令,並在給定外部DTE實例的情況下,可以調用DTE.ExecuteCommand(“ MyAddIn.MyCommand”)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM