2010-05-03 31 views
1

我有時需要以超出Visual Studio正則表達式能力的方式(例如,依賴於之前在文件或其他文件內容中看到的模式)搜索模式代碼。所以我使用Perl來分析源代碼和輸出匹配行,以及文件名和行號。如何在Visual Studio中將外部腳本輸出鏈接到代碼?

由於這與Visual Studio的搜索功能所產生的格式完全相同,我不知道是否有一種方法可以重複我可以雙擊某一行的功能,並且它將在上下文中顯示該行在Visual Studio中。有任何想法嗎?

回答

0

一位同事指了我一篇文章Writing to the Output Window From a Visual Studio .NET Add-in。有一個名爲「Visual Studio插件」的Visual Studio項目類型,我可以使用它編寫自己的加載項,它可以調用我的Perl腳本,捕獲腳本的輸出並將其發送到Visual Studio輸出窗口。

如果我可以將我的Perl腳本編譯爲.NET,那麼一個更清潔的選擇是,然後整個加載項可以在Perl中,我不必調用外部進程。

1

您可以使用Perl的Win32 :: GUI來模擬一個與搜索實用程序完全相同的窗口,以用作Perl程序的前端。這將允許您雙擊搜索結果並使用這些結果執行操作。看一下this link的方法可以轉到VS中文件中的某一行。這裏有一個簡單的例子:

use strict; 
use Win32::GUI; 

     #example data structure containing the search text to print, the file location, and the line number for the search text 
my $items = [ 
      ['first hit', 'C:\file.cs', '30'], 
      ['second hit', 'C:\anotherfile.cs', '245'], 
      ['third hit', 'C:\file.cs', '16'] 
      ]; 

my $main = Win32::GUI::Window->new(
            -width => 250, 
            -height => 250 
           ); 

my $listbox = $main->AddListbox(
           -name => 'search_hits', 
           -top => '10', 
           -left => '10', 
           -width => '100', 
           -height => '100', 
           ); 

foreach my $item(@$items){ 
    $listbox->InsertItem($item->[0]); 
} 

$main->Show(); 
Win32::GUI::Dialog(); 


sub search_hits_DblClick{ 
    my $index_selected = $listbox->GetCurSel(); 
    exec('devenv /edit '.$items->[$index_selected]->[1].' /command "edit.goto '.$items->[$index_selected]->[2].'"'); 
} 
0

是的。只要確保你遵循相同的格式:

文件名(行號):...

當這個出現在輸出窗口中,你應該能夠在其上雙擊,並採取適當的在文件中的行。

+0

但我怎樣才能讓我的腳本的輸出出現在VS輸出窗口? – JoelFan 2010-05-03 17:50:47

+0

你的問題真的是關於在VS輸出窗口中獲取外部命令的輸出嗎?你應該更新你的問題來明確地說。 :) – 2010-05-03 21:07:30

相關問題