EnvDTE dll之间的冲突

时间:2013-12-31 13:15:01

标签: c# dll reference alias visual-studio-addins

我有一个视觉工作室的插件,当用户点击右键菜单时,会为用户项目添加一个配置选项,并在他运行项目时执行某些操作:

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;

    events = _applicationObject.Events;
    dbgEvents = events.DebuggerEvents;

    if (!registered)
    {
        dbgEvents.OnEnterRunMode += new _dispDebuggerEvents_OnEnterRunModeEventHandler(DebuggerEvents_OnEnterRunMode);
        registered = true;
    }
    if ((connectMode == ext_ConnectMode.ext_cm_AfterStartup))
    {
        //add right click menu
    }
}
//...
//when click on the right click menu
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
    handled = false;
    if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
    {
        if (commandName == _addInInstance.ProgID + "." + PROJECT_COMMAND_NAME)
        {
            //...
            //add configuration option
            Solution2 sol = (Solution2)_applicationObject.Solution;
            var pro = sol.Projects.Item(1).Object;
            var tool = pro.Configurations.item(ConfigName).Tools("VCCLCompilerTool");
            //...

            handled = true;
            return;
        }
    }
}

...

void DebuggerEvents_OnEnterRunMode(dbgEventReason Reason)
{
    if (Reason == dbgEventReason.dbgEventReasonLaunchProgram || (Reason == dbgEventReason.dbgEventReasonGo && isLunchProgram))
    {
        //do something
    }
}

private EnvDTE.Events events;
private EnvDTE.DebuggerEvents dbgEvents;
//...
private AddIn _addInInstance;
private OutputWindowPane _outpuWindow;

pro.Configurations中的“配置”属性存在于:

  

C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ PublicAssemblies \ EnvDTE.dll

但是当有引用时,DebuggerEvents_OnEnterRunMode()事件不会触发。 我用

替换了这个引用
  

c:\ Windows \ assembly \ GAC \ EnvDTE \ 8.0.0.0__b03f5f7f11d50a3a \ envdte.dll

现在调用了该事件,但Configurations属性未定义。 所以我加了两个。

为了避免同一名称空间之间的冲突,根据two different DLL with same namespacealiases中的说明,我定义了

Alias属性
  

c:\ Windows \ assembly \ GAC \ EnvDTE \ 8.0.0.0__b03f5f7f11d50a3a \ envdte.dll

作为X,并添加行extern alias X;,但问题是当我尝试写

var tool = pro.X::EnvDTE.Configurations.item(ConfigName).Tools("VCCLCompilerTool");

var tool = pro.(X::EnvDTE.Configurations).item(ConfigName).Tools("VCCLCompilerTool");

我收到编译错误:

  

对象不包含'X'的定义,并且没有扩展方法'X'可以找到接受'object'类型的第一个参数(你是否缺少using指令或汇编引用?)。

我该怎么办?

0 个答案:

没有答案