在Visual Studio 2017 C#中自动执行搜索命令

问题描述:

我需要从解决方案"中搜索一长串短语.因此,有没有一种方法可以自动执行此搜索,而不是使用Ctr + Shift + F命令手动执行此操作?由于发现的大多数内容都是编写代码以从文件中进行搜索,所以我想使用Visual Studio在其解决方案中进行搜索.谢谢!!

I need to search for a long list of phrases from a Solution. So instead of using the Ctr+Shift+F command to do it manually, is there a way to automate this search? As most I found was writing codes to search from a file, I want to use visual studio to search within its Solution. Thank you!!

您可以使用 Visual Commander 扩展名,它看起来像:

You can use DTE.Find object to set search options and invoke search. With my Visual Commander extension it looks like:

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
    DTE.Find.FindWhat = @"Test";
    DTE.Find.Target = EnvDTE.vsFindTarget.vsFindTargetSolution;

    DTE.Find.Action = EnvDTE.vsFindAction.vsFindActionFindAll;
    DTE.Find.Backwards = false;
    DTE.Find.FilesOfType = @"";
    DTE.Find.KeepModifiedDocumentsOpen = false;
    DTE.Find.MatchCase = false;
    DTE.Find.MatchInHiddenText = true;
    DTE.Find.MatchWholeWord = false;
    DTE.Find.PatternSyntax = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxLiteral;
    DTE.Find.ReplaceWith = @"";
    DTE.Find.ResultsLocation = EnvDTE.vsFindResultsLocation.vsFindResults1;
    DTE.Find.SearchSubfolders = true;
    DTE.Find.SearchPath = @"Entire Solution";
    DTE.Find.Execute();     
}