简体   繁体   中英

Automate search command in Visual Studio 2017 C#

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!!

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();     
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM