【发布时间】:2014-03-13 13:59:32
【问题描述】:
我已经编写了一个 VS 2012 插件,现在我想获取打开插件时点击的文件。
这是 OnConnection 方法:
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if (connectMode == ext_ConnectMode.ext_cm_UISetup)
{
object[] contextGUIDS = new object[] { };
Commands2 commands = (Commands2)_applicationObject.Commands;
Microsoft.VisualStudio.CommandBars.CommandBar standardToolBar =
((Microsoft.VisualStudio.CommandBars.CommandBars)
_applicationObject.CommandBars)["Reference Item"];
try
{
//Add a command to the Commands collection:
Command command = commands.AddNamedCommand2(
_addInInstance,
"ProxyClassCreatorAddin",
"ProxyClassCreatorAddin",
"Executes the command for ProxyClassCreatorAddin",
true,
2677,
ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled,
(int)vsCommandStyle.vsCommandStylePictAndText,
vsCommandControlType.vsCommandControlTypeButton);
//Add a control for the command to the tools menu:
if ((command != null) && (standardToolBar != null))
{
CommandBarControl ctrl =
(CommandBarControl)command.AddControl(standardToolBar, 1);
ctrl.TooltipText = "Executes the command for MyAddin";
}
}
catch (System.ArgumentException)
{
//If we are here, then the exception is probably because a command with that name
// already exists. If so there is no need to recreate the command and we can
// safely ignore the exception.
}
}
}
所以用户在选定的引用上单击鼠标右键,然后我的插件启动,但 varIn(Exec 方法)为空,我如何获取选定引用的文件/文件名/路径?
编辑:VSIX 是不可能的
【问题讨论】:
-
考虑制作 VSIX 扩展而不是插件。
标签: c# visual-studio-2012 visual-studio-addins