一个可能的解决方案是创建一个新的菜单项与Visual Studio插件,这样当你在一条线上单击,然后选择此菜单选项,您可以执行一个动作(如读取和解析线和开放文件)。这是可以做到如下:
文件 - >新建项目 - >其他类型 - >扩展 - > Visual Studio的插件,以及实施IDTCommandTarget
Commands2 commands = (Commands2)_applicationObject.Commands;
object[] contextGUIDS = new object[] { };
CommandBars cmdBars = (CommandBars)(_applicationObject.CommandBars);
CommandBar vsBarProject = cmdBars["Code Window"];
scenarioCommand = commands.AddNamedCommand2(_addInInstance, "OpenScenario", "Open scenario", "Open scenario data", true);
scenarioCommand.AddControl(vsBarProject);
然后在exec方法,只是读行,得到的文件路径和:
Process.Start(resource)
当然,只显示菜单选项,如果是在QueryStatus方法specFlow文件:
dynamic docName = _applicationObject.ActiveDocument.FullName;
if (CmdName == OpenScenarioCmd && !((string)docName).EndsWith(".feature"))
{
StatusOption = (vsCommandStatus)vsCommandStatus.vsCommandStatusInvisible;
}
else if (CmdName == OpenScenarioCmd)
{
StatusOption = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
}
它并不完美,因为你必须表现出菜单,但它的工作原理。
是的,这应该工作,但我不能改变文件通过相对路径引用的方式,因为这些文件版本,这样他们就可以在不同的基本路径。我找到了解决办法,我会回答自己 – danijepg