Beispiel #1
0
        public async Task <bool> BuildSolution()
        {
            DTE           dte           = (DTE)_serviceProvider.GetService(typeof(DTE));
            SolutionBuild solutionBuild = dte.Solution.SolutionBuild;

            string solutionConfiguration = solutionBuild.ActiveConfiguration.Name;

            await TRD.Tasks.Task.Factory.StartNew(() =>
                                                  solutionBuild.Build(true),
                                                  TaskCreationOptions.LongRunning);

            bool compiledOK = (solutionBuild.LastBuildInfo == 0);

            return(compiledOK);
        }
Beispiel #2
0
        /// <summary>
        /// Build the current Visual Studio solution.
        /// </summary>
        /// <returns>true if built the solution successfully, false otherwise</returns>
        public bool BuildSolution()
        {
            bool result;

            try
            {
                DTE2 dte2 = (DTE2)Package.GetGlobalService(typeof(SDTE));
                //dte2.ExecuteCommand("Build.BuildSolution");
                SolutionBuild sb = dte2.Solution.SolutionBuild;
                sb.Build(true);
                result = (sb.LastBuildInfo == 0);
            }
            catch (Exception e)
            {
                WriteToOutput("Error building the solution. " + e.Message);
                result = false;
            }
            return(result);
        }
Beispiel #3
0
        public override bool Build()
        {
            try
            {
                //  _applicationObject.ExecuteCommand("Build.BuildSelection", "");
                Project   = (Project)((Array)Dte.ActiveSolutionProjects).GetValue(0);
                VsProject = ((VSProject2)(Project.Object));

                if (!ExecuteBeforeBuild())
                {
                    return(false);
                }

                Solution      = (Solution2)Dte.Solution;
                SolutionBuild = (SolutionBuild2)Solution.SolutionBuild;

                //sb2.BuildProject(sb2.ActiveConfiguration.Name, prj.UniqueName, true);
                SolutionBuild.Build(true);
                //_dte.ExecuteCommand("Build.RebuildSolution");

                if (SolutionBuild.LastBuildInfo != 0)
                {
                    return(false);
                }

                if (!BuildManifest())
                {
                    return(false);
                }

                ExecuteAfterRelease();
                return(true);
            }
            catch (Exception ex)
            {
                OutputMessage(ex.Message);
                Logger.WriteExceptionLog(ex.Message + Environment.NewLine + ex.StackTrace);
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace, Common.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
        public static void NRL()
        {
            try {
                // Current AutoCAD Document, Database and Editor.
                Autodesk.AutoCAD.ApplicationServices.Document doc = Application.DocumentManager.MdiActiveDocument;
                Database db = doc.Database;
                Editor   ed = doc.Editor;

                // Get running Visual Studio instances (using helper class).
                IDictionary <string, _DTE> vsInstances = RunningObjectTable.GetRunningVSIDETable();

                // Check for no Visual Studio instances.
                if (vsInstances.Count == 0)
                {
                    ed.WriteMessage("\nNo running Visual Studio instances were found. *Cancel*");
                    return;
                }

                // Create list of solution names.
                List <string> solNames = new List <string>();
                foreach (KeyValuePair <string, _DTE> item in vsInstances)
                {
                    solNames.Add(Path.GetFileNameWithoutExtension(item.Value.Solution.FullName));
                }

                // Check if all solution names equal "".
                // i.e. no solutions loaded in any of the Visual Studio instances.
                bool allSolNamesEmpty = true;
                foreach (string name in solNames)
                {
                    if (name != "")
                    {
                        allSolNamesEmpty = false;
                        break;
                    }
                }
                if (allSolNamesEmpty == true)
                {
                    ed.WriteMessage("\nNo active Visual Studio solutions were found. *Cancel*");
                    return;
                }

                // Prompt user to select solution.
                PromptKeywordOptions pko = new PromptKeywordOptions("\nSelect Visual Studio instance to increment:");
                pko.AllowNone = false;
                foreach (string name in solNames)
                {
                    if (name != "")
                    {
                        pko.Keywords.Add(name);
                    }
                }
                if (defaultKeyword == "" || solNames.Contains(defaultKeyword) == false)
                {
                    int index = 0;
                    while (solNames[index] == "")
                    {
                        index++;
                    }
                    pko.Keywords.Default = solNames[index];
                }
                else
                {
                    pko.Keywords.Default = defaultKeyword;
                }
                PromptResult pr = ed.GetKeywords(pko);
                if (pr.Status != PromptStatus.OK)
                {
                    return;
                }
                defaultKeyword = pr.StringResult;

                // Use prompt result to set Visual Studio instance variable.
                _DTE dte = vsInstances.ElementAt(solNames.IndexOf(pr.StringResult)).Value;

                // Use custom WaitCursor class for long operation.
                using (WaitCursor wc = new WaitCursor()) {
                    // Active Visual Studio Document.
                    EnvDTE.Document vsDoc = dte.ActiveDocument;
                    if (vsDoc == null)
                    {
                        ed.WriteMessage(String.Format("\nNo active document found for the '{0}' solution. *Cancel*",
                                                      pr.StringResult));
                        return;
                    }

                    // Active Visual Studio Project.
                    Project prj = vsDoc.ProjectItem.ContainingProject;

                    // Debug directory - i.e. \bin\Debug.
                    string debugDir = prj.FullName;
                    debugDir = Path.GetDirectoryName(debugDir);
                    debugDir = Path.Combine(debugDir, @"bin\Debug");

                    // NetReload directory - i.e. \bin\Debug\NetReload.
                    string netReloadDir = Path.Combine(debugDir, "NetReload");

                    // Create NetReload directory if it doens't exist.
                    if (Directory.Exists(netReloadDir) == false)
                    {
                        Directory.CreateDirectory(netReloadDir);
                    }

                    // Temporary random assembly file name (check it doesn't already exist).
                    string tempAssemblyName;
                    do
                    {
                        tempAssemblyName = Path.GetRandomFileName();
                    } while (File.Exists(Path.Combine(netReloadDir, tempAssemblyName + ".dll")));

                    // Project's initial "AssemblyName" property setting.
                    string initAssemblyName = prj.Properties.Item("AssemblyName").Value as string;

                    // Set project's "AssemblyName" property to temp value.
                    prj.Properties.Item("AssemblyName").Value = tempAssemblyName;

                    // Build solution.
                    SolutionBuild solBuild = dte.Solution.SolutionBuild;
                    solBuild.Build(true);

                    // Re-set project's "AssemblyName" property back to initial value.
                    prj.Properties.Item("AssemblyName").Value = initAssemblyName;

                    // Check if build was successful.
                    // # Note: LastBuildInfo property reports number of projects in the solution that failed to build.
                    if (solBuild.LastBuildInfo != 0)
                    {
                        ed.WriteMessage(String.Format("\nBuild failed for the '{0}' solution. *Cancel*",
                                                      pr.StringResult));
                        return;
                    }

                    // Move new assembly (.dll) from Debug directory to NetReload directory.
                    File.Move(
                        Path.Combine(debugDir, tempAssemblyName + ".dll"),
                        Path.Combine(netReloadDir, tempAssemblyName + ".dll")
                        );

                    // Move new .pdb file from Debug directory to NetReload directory.
                    File.Move(
                        Path.Combine(debugDir, tempAssemblyName + ".pdb"),
                        Path.Combine(netReloadDir, tempAssemblyName + ".pdb")
                        );

                    // NETLOAD new assembly file.
                    System.Reflection.Assembly.LoadFrom(Path.Combine(netReloadDir, tempAssemblyName + ".dll"));

                    // Output summary.
                    ed.WriteMessage("\nNETRELOAD complete for {0}.dll.", initAssemblyName);
                }
            } catch (Autodesk.AutoCAD.Runtime.Exception ex) {
                // Catch AutoCAD exception.
                Application.ShowAlertDialog(String.Format("ERROR" +
                                                          "\nMessage: {0}\nErrorStatus: {1}", ex.Message, ex.ErrorStatus));
            } catch (System.Exception ex) {
                // Catch Windows exception.
                Application.ShowAlertDialog(String.Format("ERROR" +
                                                          "\nMessage: {0}", ex.Message));
            }
        }
Beispiel #5
0
 public void Build(bool WaitForBuildToFinish = false)
 {
     _build.Build(WaitForBuildToFinish);
 }