public virtual 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 OpenSolution(object sender, DoWorkEventArgs e) { bwAsync = sender as BackgroundWorker; EnvDTE80.DTE2 dte = null; Dictionary <string, IUMLElement> listElements = new Dictionary <string, IUMLElement>(); try { dte = (EnvDTE80.DTE2)Microsoft.VisualBasic.Interaction.CreateObject("VisualStudio.DTE.8.0", ""); Solution2 soln = (Solution2)dte.Solution; soln.Open(File); SolutionBuild2 build = (SolutionBuild2)soln.SolutionBuild; addMessageBackgroundWorker(0, "Building Solution..."); build.SolutionConfigurations.Item("Debug").Activate(); build.Clean(true); build.Build(true); UMLModel model = Helper.GetCurrentElement <UMLModel>(); if (build.LastBuildInfo == 0 && model != null) { IUMLElement solutionUML = new UMLPackage(); solutionUML.Name = Path.GetFileName(soln.FileName); solutionUML.Owner = model; listElements.Add(solutionUML.Name, solutionUML); for (int i = 1; i <= soln.Projects.Count; i++) { Project project = soln.Projects.Item(i); if (project.Properties != null) { string fullPath = (string)project.Properties.Item("FullPath").Value; string outputfileName = (string)project.Properties.Item("OutputFileName").Value; Assembly assembly = Assembly.LoadFile(fullPath + @"Bin\Debug\" + outputfileName); IUMLElement projectUML = new UMLPackage(); projectUML.Name = project.Name; listElements.Add(project.Name, projectUML); projectUML.Owner = solutionUML; addMessageBackgroundWorker(0, "Processing Types: \n" + project.Name); foreach (Type type in assembly.GetTypes()) { if (type.MemberType == MemberTypes.TypeInfo) { IUMLElement element = null; if (type.IsEnum && IncludeEnumeration) { element = new UMLEnumeration(); element.Name = type.Name; ((UMLEnumeration)element).Literals = GetLiterals(type); } else { if (type.IsClass && IncludeClass) { element = new UMLClass(); element.Name = type.Name; ((UMLClass)element).Attributes = GetProperties(type); ((UMLClass)element).Attributes.AddRange(GetStaticAndConstants(type)); ((UMLClass)element).Methods = GetMethods(type); if (type.IsGenericType) { element.Name = element.Name.Substring(0, element.Name.IndexOf("`")); element.Name += "<"; foreach (Type t in type.GetGenericArguments()) { element.Name += t.Name + ","; } element.Name = element.Name.TrimEnd(','); element.Name += ">"; } } else if (type.IsInterface && IncludeInterface) { element = new UMLInterface(); element.Name = type.Name; ((UMLInterface)element).Attributes = GetProperties(type); } } if (element != null) { IUMLElement owner = null; if (type.Namespace == null) { owner = projectUML; } else if (listElements.ContainsKey(type.Namespace)) { owner = listElements[type.Namespace]; } else { owner = new UMLPackage(); //if(type.Namespace.Contains(projectUML.Name)) //{ // owner.Name = type.Namespace.Replace(projectUML.Name, ""); //} owner.Stereotype = "ClassPackage"; owner.Name = type.Namespace; owner.Owner = projectUML; listElements.Add(type.Namespace, owner); } element.Owner = owner; if ((type.Attributes & TypeAttributes.Public) == TypeAttributes.Public) { element.Visibility = Visibility.Public; } else { element.Visibility = Visibility.Private; } XmlNode node = DocsByReflection.XMLFromType(type); if (node != null) { element.Documentation = node.InnerXml.Trim(); } if (!listElements.ContainsKey(type.Namespace + "." + type.Name)) { listElements.Add(type.Namespace + "." + type.Name, element); } } } } } } } else { // Error Build } soln.Close(true); } catch (SystemException ex) { //MessageBox.Show("ERROR: " + ex); } finally { if (dte != null) { dte.Quit(); } } Helper.BeginUpdate(); addMessageBackgroundWorker(0, "Init import..."); int pos = 0; foreach (IUMLElement element in listElements.Values) { pos++; addMessageBackgroundWorker((pos * 100) / listElements.Count, "Creating: \n" + element.Name); element.GetType().InvokeMember("Save", BindingFlags.Default | BindingFlags.InvokeMethod, null, element, new object[] { }); } addMessageBackgroundWorker(100, "End import"); Helper.EndUpdate(); }