mardi 13 mai 2014

c# - conflit entre EnvDTE dll - Stack Overflow


I have an Addin to visual studio that adds a configuration option to the user project when the user clicks on right menu click, and does something when he runs his project:


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;

The Configurations property in pro.Configurations exists in:



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



but when there is reference to it, the DebuggerEvents_OnEnterRunMode() event doesn't fire. I replaced this reference with



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



and now the event called, but the Configurations property is undefined. So I added both.


In order to avoid conflict between the same namespace, according the instructions in two different DLL with same namespace and in aliases, I define the Alias property of



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



as X, and add the line extern alias X;, but the problem is that when I try to write


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

or


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

I get a compile error:



object does not contain a definition for 'X' and no extension method 'X' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?).



what should I do?



I have an Addin to visual studio that adds a configuration option to the user project when the user clicks on right menu click, and does something when he runs his project:


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;

The Configurations property in pro.Configurations exists in:



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



but when there is reference to it, the DebuggerEvents_OnEnterRunMode() event doesn't fire. I replaced this reference with



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



and now the event called, but the Configurations property is undefined. So I added both.


In order to avoid conflict between the same namespace, according the instructions in two different DLL with same namespace and in aliases, I define the Alias property of



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



as X, and add the line extern alias X;, but the problem is that when I try to write


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

or


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

I get a compile error:



object does not contain a definition for 'X' and no extension method 'X' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?).



what should I do?


0 commentaires:

Enregistrer un commentaire