Esempio n. 1
0
        void Find(string pattern, vsFindTarget target)
        {
            if (Dte == null)
            {
                return;
            }

            Dte.Find.Target            = target;
            Dte.Find.PatternSyntax     = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
            Dte.Find.Action            = vsFindAction.vsFindActionFindAll;
            Dte.Find.ResultsLocation   = vsFindResultsLocation.vsFindResults1;

            Dte.Find.FindWhat          = pattern;
            Dte.Find.MatchCase         = false;
            Dte.Find.MatchWholeWord    = false;
            Dte.Find.MatchInHiddenText = true;
            Dte.Find.SearchSubfolders  = true;
            Dte.Find.FilesOfType       = "*.*";

            Dte.ExecuteCommand("View.FindResults1");
            Dte.Find.Execute();
        }
Esempio n. 2
0
        private void AddPublicKeyToInternalsVisible(List <Project> projectList, string publicKey)
        {
            EnvDTE.DTE dte  = GetService <EnvDTE.DTE>(true);
            Find2      find = (Find2)dte.Find;

            // Save original settings
            vsFindAction          origAction      = find.Action;
            string                origFilesOfType = find.FilesOfType;
            string                origFindWhat    = find.FindWhat;
            bool                  origKeepModifiedDocumentsOpen = find.KeepModifiedDocumentsOpen;
            bool                  origMatchCase        = find.MatchCase;
            bool                  origMatchHiddenText  = find.MatchInHiddenText;
            bool                  origMatchWholeWord   = find.MatchWholeWord;
            vsFindPatternSyntax   origPatternSyntax    = find.PatternSyntax;
            string                origReplaceWith      = find.ReplaceWith;
            vsFindResultsLocation origResultsLocation  = find.ResultsLocation;
            string                origSearchPath       = find.SearchPath;
            bool                  origSearchSubfolders = find.SearchSubfolders;
            vsFindTarget          origTarget           = find.Target;

            try
            {
                // match InternalsVisibleTo(" followed by anything (non greedy) up until the first comma, if any, as a tag
                // match the remaining non " chars up until the first " (re = "(,[^""]*)*", no "?" operator is supported by VS regex engine)
                // by leaving anything after the coma outside the tag, existing public keys will be ignored
                // by matching InternalsVisibleTo("[content]"), having the attribute together with other attributes is not an issue
                find.FindWhat = @"{InternalsVisibleTo\("".@}(,[^""]*)*""";
                if (publicKey == null)
                {
                    find.ReplaceWith = @"\1""]";
                }
                else
                {
                    find.ReplaceWith = @"\1, PublicKey=" + publicKey + @"""";
                }

                find.Action      = vsFindAction.vsFindActionReplaceAll;
                find.FilesOfType = "AssemblyInfo.*";
                find.KeepModifiedDocumentsOpen = false;
                find.MatchCase             = false;
                find.MatchInHiddenText     = true;
                find.MatchWholeWord        = false;
                find.PatternSyntax         = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
                find.ResultsLocation       = vsFindResultsLocation.vsFindResults1;
                find.SearchSubfolders      = true;
                find.Target                = vsFindTarget.vsFindTargetFiles;
                find.WaitForFindToComplete = true;

                foreach (Project project in projectList)
                {
                    string projectPropertiesPath = Path.GetDirectoryName(project.FileName);
                    find.SearchPath = projectPropertiesPath;
                    vsFindResult result = find.Execute();
                    Debug.WriteLine(project.Name + " " + result.ToString());
                }
            }
            finally
            {
                // Restore original settings
                find.Action      = origAction;
                find.FilesOfType = origFilesOfType;
                find.FindWhat    = origFindWhat;
                find.KeepModifiedDocumentsOpen = origKeepModifiedDocumentsOpen;
                find.MatchCase         = origMatchCase;
                find.MatchInHiddenText = origMatchHiddenText;
                find.MatchWholeWord    = origMatchWholeWord;
                find.PatternSyntax     = origPatternSyntax;
                find.ReplaceWith       = origReplaceWith;
                find.ResultsLocation   = origResultsLocation;
                find.SearchPath        = origSearchPath;
                find.SearchSubfolders  = origSearchSubfolders;
                find.Target            = origTarget;
            }
        }