2017-07-06 161 views
0

我有一組上使用Visual Studio的specflow測試,其中一些有步驟,看起來像:擴展爲Specflow在Visual Studio

Given the data in file /foo/bar/data.txt 

我想實現一個Visual Studio擴展,所以我可以點擊在/foo/bar/data.txt上並打開文件。

我不得不使用像一個Visual Studio文本裝飾的一個模糊的想法,但我真的不知道,如果有一個簡單的方法。此外,我正在尋找的是在Visual Studio 2013及以上的作品,並點綴沒有在老版本的,據我知道支持的解決方案。有任何想法嗎?

回答

0

一個可能的解決方案是創建一個新的菜單項與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; 
} 

它並不完美,因爲你必須表現出菜單,但它的工作原理。

0

如果前綴文件的路徑://它會成爲一個可點擊的鏈接。像使用任何URL一樣,用「%20」替換空格。

Sample screenshot

我知道這不是回答你問的問題,但也許你並不需要實現的延伸?

+0

是的,這應該工作,但我不能改變文件通過相對路徑引用的方式,因爲這些文件版本,這樣他們就可以在不同的基本路徑。我找到了解決辦法,我會回答自己 – danijepg