/// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool RunSolution(bool debug)
        {
            try{
                //EnvDTE80.Events2 a;
                //a.DebuggerEvents.OnEnterRunMode

                EnvDTE80.Solution2      s = this.Application.Solution as EnvDTE80.Solution2;
                EnvDTE80.SolutionBuild2 b = this.Application.Solution.SolutionBuild as EnvDTE80.SolutionBuild2;
                if (debug)
                {
                    b.Debug();
                    Wait(5);
                    while (this.Application.Debugger.CurrentMode == EnvDTE.dbgDebugMode.dbgRunMode)
                    {
                        Wait(1);
                    }
                }
                else
                {
                    b.Run();
                }
                return(true);
            }
            catch (System.Exception ex) {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return(false);
            }
        }
 public int GetErrorCountBuilding()
 {
     try{
         EnvDTE80.SolutionBuild2 b = this.Application.Solution.SolutionBuild as EnvDTE80.SolutionBuild2;
         return(b.LastBuildInfo);
     }
     catch (System.Exception ex) {
         System.Windows.Forms.MessageBox.Show(ex.Message);
         return(-1);
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public bool BuildSolution()
 {
     try{
         EnvDTE80.SolutionBuild2 b = this.Application.Solution.SolutionBuild as EnvDTE80.SolutionBuild2;
         b.Build(true);
         return(b.LastBuildInfo == 0);
     }
     catch (System.Exception ex) {
         System.Windows.Forms.MessageBox.Show(ex.Message);
         return(false);
     }
 }
Exemple #4
0
        /// [disconnect from VS]


        public ProjectInfo ReadSettingsOfAllProjects()
        {
            ProjectInfo projectInfo = new ProjectInfo();

            WriteLine(3, "ReadSettingsOfAllProjects-Begin");
            try
            {
                if (dte == null)
                {
                    WriteLine(1, "dte is null (checking for projects is not possible)");
                    return(projectInfo);
                }
                if (dte.Solution == null)
                {
                    WriteLine(1, "dte.Solution is null (checking for projects is not possible)");
                    return(projectInfo);
                }
                if (dte.Solution.SolutionBuild == null)
                {
                    WriteLine(1, "dte.Solution.SolutionBuild is null (checking for projects is not possible)");
                    return(projectInfo);
                }
                if (dte.Solution.SolutionBuild.ActiveConfiguration == null)
                {
                    WriteLine(1, "dte.Solution.SolutionBuild.ActiveConfiguration is null (checking for projects is not possible)");
                    return(projectInfo);
                }

                projectInfo.solutionFullPath = dte.Solution.FileName;

                /// [get config name]
                //Get name of config (e.g. "Debug", "Release"
                string configName = dte.Solution.SolutionBuild.ActiveConfiguration.Name;
                /// [get config name]

                string msg = "";

                /// [get name startup project]
                EnvDTE80.SolutionBuild2 sb = (EnvDTE80.SolutionBuild2)dte.Solution.SolutionBuild;
                if (sb == null)
                {
                    WriteLine(1, "SolutionBuild is null (checking for projects is not possible)");
                    return(projectInfo);
                }

                // for further processing extract the name without path and extension
                // e.g. nameStartupProject = "TestRunner"
                // (extraction code not shown here)
                /// [get name startup project]

                // To simple solution which does not work for startup projects within a filter
                //EnvDTE.Project startupProj = dte.Solution.Item(msg);

                /// [get startup project]
                // Perform recursive search for the startup project through all solution filters:
                EnvDTE.Project[] projects = GetAllProjects(false);
                /// [get startup project]

                //iterate through main projects
                foreach (var dteProject in projects)
                {
                    var project = new Project();
                    project.DTEProject  = dteProject;
                    project.ProjectName = dteProject.Name;

                    var projectFiles = new List <FileInfo>();

                    foreach (EnvDTE.ProjectItem fileItem in GetAllProjectItemsFromKind(project.DTEProject, EnvDTE.Constants.vsProjectItemKindPhysicalFile))
                    {
                        for (short i = 0; i < fileItem.FileCount; i++)
                        {
                            var fileInfo = new FileInfo(fileItem.FileNames[i]);
                            projectFiles.Add(fileInfo);
                        }
                    }
                    project.ProjectFiles = projectFiles.Distinct().ToArray();

                    try
                    {
                        project.SourceDirPath = System.IO.Path.GetDirectoryName(dteProject.FullName);
                    } catch (Exception ex)
                    {
                        WriteLine(3, "ReadSettingsOfAllProjects EXCEPTION: " + ex.ToString());
                        continue;
                    }

                    EnvDTE.ConfigurationManager cm = dteProject.ConfigurationManager;
                    if (cm == null)
                    {
                        WriteLine(1, "No ConfigurationManager found");
                        WriteLine(3, "ReadSettingsOfAllProjects: no ConfigurationManager found");
                        continue;
                    }
                    if (cm.ActiveConfiguration == null)
                    {
                        WriteLine(1, "No ActiveConfiguration found");
                        WriteLine(3, "ReadSettingsOfAllProjects: no ActiveConfiguration found");
                        continue;
                    }
                    msg = "Platform=" + cm.ActiveConfiguration.PlatformName;
                    WriteLine(2, msg);

                    EnvDTE.Properties props = cm.ActiveConfiguration.Properties;
                    if (props != null)
                    {
                        WriteLine(2, "Now iterating over ActiveConfiguration.Properties...");

                        // Scan properties of ActiveConfiguration to be used for future extended requests
                        msg = "ReadSettingsOfStartupProject: ActiveConfiguration.Properties";
                        foreach (EnvDTE.Property p in props)
                        {
                            msg += "  " + p.Name;
                        }
                        WriteLine(2, msg);
                    }
                    /// [get exe path]
                    // Get full path of executable depending on found
                    // startup project and configuration (Debug/Release)
                    Microsoft.VisualStudio.VCProjectEngine.VCProject vcProj =
                        (Microsoft.VisualStudio.VCProjectEngine.VCProject)dteProject.Object;
                    Microsoft.VisualStudio.VCProjectEngine.IVCCollection configs =
                        (Microsoft.VisualStudio.VCProjectEngine.IVCCollection)vcProj.Configurations;
                    Microsoft.VisualStudio.VCProjectEngine.VCConfiguration config =
                        FindConfig(configs, configName);
                    if (config == null)
                    {
                        WriteLine(1, "Config " + configName + " not found");
                        continue;
                    }
                    msg = "PrimaryOutput (FullExePath)=" + config.PrimaryOutput;
                    WriteLine(2, msg);
                    /// [get exe path]
                    project.FullExePath = config.PrimaryOutput;
                    string delimiter  = "/\\";
                    int    posPathEnd = project.FullExePath.LastIndexOfAny(delimiter.ToCharArray());
                    if (posPathEnd > 0)
                    {
                        project.TargetDirPath = project.FullExePath.Substring(0, posPathEnd);
                    }
                    msg = "ReadSettingsOfAllProjects: OutputPath=" + project.TargetDirPath;
                    WriteLine(2, msg);

                    // Scan properties to be used for future extended requests
                    msg = "ReadSettingsOfAllProjects: startupProj.Properties";
                    foreach (EnvDTE.Property p in dteProject.Properties)
                    {
                        msg += "  " + p.Name;
                    }
                    WriteLine(3, msg);
                    projectInfo.AddProject(project);
                }
                projectInfo.config = configName;

                WriteLine(3, "ReadSettingsOfAllProjects-End");
            }
            catch (Exception ex)
            {
                WriteLine(1, "ReadSettingsOfAllProjects-End: EXCEPTION: " + ex.ToString());
            }
            return(projectInfo);
        }