lazy bum
lazy bum

Reputation: 79

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

Upvotes: 0

Views: 113

Answers (1)

Sergey Vlasov
Sergey Vlasov

Reputation: 27880

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

Upvotes: 1

Related Questions