Exemple #1
0
        void ProcessOpenConApp(object sender, EventArgs e)
        {
            Debug.WriteLine("Open Console App");
            DTE dte = (DTE)GetService(typeof(EnvDTE.DTE));

            var prjs = dte.Solution.Projects;

            if (prjs.Count > 0)
            {
                string s = prjs.Item(1).FullName;
                s = s.Replace(".vcxproj", ".cpp");
                dte.ItemOperations.OpenFile(s);
                dte.ActiveDocument.Activate();
                dte.Find.PatternSyntax     = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
                dte.Find.FindWhat          = "int main\\(.*\\n\\{.*\\n";
                dte.Find.Target            = vsFindTarget.vsFindTargetCurrentDocument;
                dte.Find.MatchCase         = false;
                dte.Find.MatchWholeWord    = false;
                dte.Find.Backwards         = false;
                dte.Find.MatchInHiddenText = false;
                dte.Find.Action            = vsFindAction.vsFindActionFind;
                if (dte.Find.Execute() == vsFindResult.vsFindResultNotFound)
                {
                    throw new System.Exception("vsFindResultNotFound");
                }
                dte.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close();
                TextSelection ts = (TextSelection)dte.ActiveDocument.Selection;
                ts.CharRight();
                ts.Indent();

                dte.ExecuteCommand("File.SaveAll", string.Empty);
                dte.ExecuteCommand("Build.BuildSolution");
                dte.ActiveDocument.Activate();
            }
        }
Exemple #2
0
        void ProcessOpenCSharpConApp(object sender, EventArgs e)
        {
            Debug.WriteLine("Open CSharp Console App");
            DTE dte = (DTE)GetService(typeof(EnvDTE.DTE));

            var prjs = dte.Solution.Projects;

            if (prjs.Count > 0)
            {
                // get full path of solution (including name of solution file):
                string solutionFullPathname = dte.Solution.FullName;

                // extract the directory of the solution:
                string dir = System.IO.Path.GetDirectoryName(solutionFullPathname);

                // get the name of the first project
                string projectName = dte.Solution.Projects.Item(1).Name;

                // combine the solution dir with the project dir and "program.cs":
                string programfname = System.IO.Path.Combine(dir, projectName, "program.cs");
                //System.Windows.Forms.MessageBox.Show("hello: " + programfname);

                dte.ItemOperations.OpenFile(programfname, EnvDTE.Constants.vsViewKindCode);
                var findString = @"static void Main\(string\[\] args\)\r?\n +{";

                dte.ActiveDocument.Activate();
                dte.Find.PatternSyntax     = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
                dte.Find.FindWhat          = findString;
                dte.Find.Target            = vsFindTarget.vsFindTargetCurrentDocument;
                dte.Find.MatchCase         = false;
                dte.Find.MatchWholeWord    = false;
                dte.Find.Backwards         = false;
                dte.Find.MatchInHiddenText = false;
                dte.Find.Action            = vsFindAction.vsFindActionFind;
                if (dte.Find.Execute() == vsFindResult.vsFindResultNotFound)
                {
                    throw new System.Exception("vsFindResultNotFound");
                }
                dte.Windows.Item("{CF2DDC32-8CAD-11D2-9302-005345000000}").Close();
                TextSelection ts = (TextSelection)dte.ActiveDocument.Selection;
                ts.CharRight();
                ts.Indent();

                dte.ExecuteCommand("File.SaveAll", string.Empty);
                dte.ExecuteCommand("Build.BuildSolution");
                dte.ActiveDocument.Activate();
            }
        }