Beispiel #1
0
        private void BuildEvents_OnBuildProjectBegin(object sender, BuildProjectEventArgs e)
        {
            try
            {
                ProjectItem currentProject = e.ProjectItem;
                currentProject.State           = e.ProjectState;
                currentProject.BuildFinishTime = null;
                currentProject.BuildStartTime  = e.EventTime;

                _viewModel.OnBuildProjectBegin();
                if (_buildContext.BuildScope == BuildScopes.BuildScopeSolution &&
                    (_buildContext.BuildAction == BuildActions.BuildActionBuild ||
                     _buildContext.BuildAction == BuildActions.BuildActionRebuildAll))
                {
                    currentProject.BuildOrder = _viewModel.BuildProgressViewModel.CurrentQueuePosOfBuildingProject;
                }

                if (!_viewModel.ProjectsList.Contains(currentProject))
                {
                    _viewModel.ProjectsList.Add(currentProject);
                }

                _viewModel.CurrentProject = currentProject;
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
            }
        }
        private static void UpdateNameProperties(Project project, ProjectItem projectItem)
        {
            try
            {
                projectItem.UniqueName = project.UniqueName;
                projectItem.Name       = project.Name;
                projectItem.FullName   = project.FullName;

                if (IsIntegrationServicesProject(project, projectItem))
                {
                    AdjustUniqueNameForExtensionProjects(project, projectItem);
                }

                try
                {
                    projectItem.FullPath = string.IsNullOrWhiteSpace(projectItem.FullName) ? null : Path.GetDirectoryName(projectItem.FullName);
                }
                catch (SystemException ex)
                {
                    // PathTooLongException, ArgumentException (invalid characters).
                    ex.TraceUnknownException();
                    projectItem.FullPath = null;
                }

                projectItem.SolutionFolder = project.GetTreePath(false) ?? @"\";
                // TODO: SolutionPath = project.GetTreePath(true);
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
            }
        }
        private static void AdjustUniqueNameForExtensionProjects(Project project, ProjectItem projectItem)
        {
            var directory     = Path.GetDirectoryName(project.UniqueName);
            var directoryName = Path.GetFileName(directory);
            var csprojName    = Path.GetFileName(project.UniqueName);

            projectItem.UniqueName = Path.Combine(directoryName, csprojName);
        }
Beispiel #4
0
        private void ProjectCopyBuildOutputFilesToClipBoard(ProjectItem projItem)
        {
            try
            {
                Project project = _dte.Solution.GetProject(x => x.UniqueName == projItem.UniqueName);
                BuildOutputFileTypes fileTypes = _packageContext.ControlSettings.ProjectItemSettings.CopyBuildOutputFileTypesToClipboard;
                if (fileTypes.IsEmpty)
                {
                    MessageBox.Show(@"Nothing to copy: all file types unchecked.", Resources.ProductName, MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                string[] filePaths = project.GetBuildOutputFilePaths(fileTypes, projItem.Configuration, projItem.Platform).ToArray();
                if (filePaths.Length == 0)
                {
                    MessageBox.Show(@"Nothing copied: selected build output groups are empty.", Resources.ProductName, MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                string[] existFilePaths = filePaths.Where(File.Exists).ToArray();
                if (existFilePaths.Length == 0)
                {
                    string msg = GetCopyBuildOutputFilesToClipboardActionMessage("Nothing copied. {0} wasn't found{1}", filePaths);
                    MessageBox.Show(msg, Resources.ProductName, MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                ClipboardHelper.SetFileDropList(existFilePaths);

                if (existFilePaths.Length == filePaths.Length)
                {
                    string msg = GetCopyBuildOutputFilesToClipboardActionMessage("Copied {0}{1}", existFilePaths);
                    MessageBox.Show(msg, Resources.ProductName, MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    string[] notExistFilePaths = filePaths.Except(existFilePaths).ToArray();
                    string   copiedMsg         = GetCopyBuildOutputFilesToClipboardActionMessage("Copied {0}{1}", existFilePaths);
                    string   notFoundMsg       = GetCopyBuildOutputFilesToClipboardActionMessage("{0} wasn't found{1}", notExistFilePaths);
                    string   msg = string.Concat(copiedMsg, Environment.NewLine, Environment.NewLine, notFoundMsg);
                    MessageBox.Show(msg, Resources.ProductName, MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            catch (Win32Exception ex)
            {
                string msg = string.Format("Error copying files to the Clipboard: 0x{0:X} ({1})", ex.ErrorCode, ex.Message);
                ex.Trace(msg);
                MessageBox.Show(msg, Resources.ProductName, MessageBoxButton.OK, MessageBoxImage.Error);
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
                MessageBox.Show(ex.Message, Resources.ProductName, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 private static bool IsIntegrationServicesProject(Project project, ProjectItem projectItem)
 {
     if (project.Kind == _GUID_SQL_INTEGRATIONG_SERVICES_PROJECT_KIND)
     {
         return(projectItem.UniqueName == projectItem.FullName);
     }
     else
     {
         return(false);
     }
 }
Beispiel #6
0
 private void RaiseCommandForSelectedProject(ProjectItem selectedProjectItem, int commandId)
 {
     try
     {
         SelectProjectInSolutionExplorer(selectedProjectItem);
         RaiseCommand((VSConstants.VSStd97CmdID)commandId);
     }
     catch (Exception ex)
     {
         ex.TraceUnknownException();
     }
 }
Beispiel #7
0
        private void SelectProjectInSolutionExplorer(ProjectItem projectItem)
        {
            var solutionExplorer = _dte2.ToolWindows.SolutionExplorer;
            var project          = _dte.Solution.GetProject(x => x.UniqueName == projectItem.UniqueName);
            var item             = solutionExplorer.FindHierarchyItem(project);

            if (item == null)
            {
                throw new ProjectNotFoundException($"Project '{projectItem.UniqueName}' not found in SolutionExplorer.");
            }
            solutionExplorer.Parent.Activate();
            item.Select(vsUISelectionType.vsUISelectionTypeSelect);
        }
Beispiel #8
0
 private void CopyErrorMessageToClipboard(ProjectItem projectItem)
 {
     try
     {
         var errors = new StringBuilder();
         foreach (var errorItem in projectItem.ErrorsBox.Errors)
         {
             errors.AppendLine(string.Format("{0}({1},{2},{3},{4}): error {5}: {6}", errorItem.File, errorItem.LineNumber, errorItem.ColumnNumber, errorItem.EndLineNumber, errorItem.EndColumnNumber, errorItem.Code, errorItem.Message));
         }
         Clipboard.SetText(errors.ToString());
     }
     catch (Exception ex)
     {
         ex.TraceUnknownException();
     }
 }
        public static void UpdateProjects(SolutionItem solutionItem, Solution solution)
        {
            solutionItem.AllProjects.Clear();

            if (solution == null)
            {
                return;
            }

            IList <Project> dteProjects;

            try
            {
                dteProjects = solution.GetProjects();
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
                return;
            }



            var projectItems = new List <ProjectItem>(dteProjects.Count);

            foreach (Project project in dteProjects)
            {
                try
                {
                    //var msBuildProject = project.GetMsBuildProject();
                    var projectItem = new ProjectItem();
                    UpdateProperties(project, projectItem);
                    projectItems.Add(projectItem);
                }
                catch (Exception ex)
                {
                    ex.TraceUnknownException();
                }
            }

            solutionItem.AllProjects.AddRange(projectItems);
        }
Beispiel #10
0
        private void BuildEvents_OnBuildProjectDone(object sender, BuildProjectEventArgs e)
        {
            if (e.ProjectState == ProjectState.BuildError && _viewModel.ControlSettings.GeneralSettings.StopBuildAfterFirstError)
            {
                _buildDistributor.CancelBuild();
            }

            try
            {
                ProjectItem currentProject = e.ProjectItem;
                currentProject.State           = e.ProjectState;
                currentProject.BuildFinishTime = DateTime.Now;
                currentProject.UpdatePostBuildProperties(e.BuildedProjectInfo);

                if (!_viewModel.ProjectsList.Contains(currentProject))
                {
                    _viewModel.ProjectsList.Add(currentProject);
                }

                var buildInfo = (IBuildInfo)sender;
                if (ReferenceEquals(_viewModel.CurrentProject, e.ProjectItem) && buildInfo.BuildingProjects.Any())
                {
                    _viewModel.CurrentProject = buildInfo.BuildingProjects.Last();
                }
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
            }

            _viewModel.UpdateIndicators(_buildContext);

            try
            {
                _viewModel.OnBuildProjectDone(e.BuildedProjectInfo);
            }
            catch (Exception ex)
            {
                ex.TraceUnknownException();
            }
        }
        public static void UpdateProperties(Project project, ProjectItem projectItem)
        {
            if (project != null)
            {
                object projObject;
                try
                {
                    projObject = project.Object;
                }
                catch (Exception ex)
                {
                    ex.TraceUnknownException();
                    projObject = null;
                }

                try
                {
                    if (projObject == null)
                    {
                        projectItem.UniqueName = project.UniqueName;
                        projectItem.Name       = project.Name;
                        return;
                    }

                    UpdateNameProperties(project, projectItem);
                    projectItem.Language   = project.GetLanguageName();
                    projectItem.CommonType = ProjectExtensions.GetProjectType(project.Kind, project.DTE.Version /* "12.0" */);
                }
                catch (Exception ex)
                {
                    ex.TraceUnknownException();
                }

                #region Set ActiveConfiguration (Configuration and Platform)

                Configuration config;
                try
                {
                    config = project.ConfigurationManager.ActiveConfiguration;
                }
                catch (Exception ex)
                {
                    ex.TraceUnknownException();
                    config = null;
                }

                if (config != null)
                {
                    projectItem.Configuration = config.ConfigurationName;
                    projectItem.Platform      = config.PlatformName;
                }
                else
                {
                    projectItem.Configuration = @"N\A";
                    projectItem.Platform      = @"N\A";
                }

                #endregion

                try
                {
                    projectItem.Framework = project.GetFrameworkString();

                    var flavourTypes = project.GetFlavourTypes().ToList();
                    projectItem.FlavourType     = string.Join("; ", flavourTypes);
                    projectItem.MainFlavourType = flavourTypes.FirstOrDefault();

                    projectItem.OutputType    = project.GetOutputType();
                    projectItem.ExtenderNames = project.GetExtenderNames();

                    projectItem.RootNamespace = project.GetRootNamespace();
                }
                catch (Exception ex)
                {
                    ex.TraceUnknownException();
                }
            }
        }