示例#1
0
        private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action)
        {
            if (action == vsBuildAction.vsBuildActionDeploy)
            {
                return;
            }

            RegisterLogger();

            CurrentBuildState = BuildState.InProgress;

            BuildStartTime  = DateTime.Now;
            BuildFinishTime = null;
            BuildAction     = (BuildActions)action;

            switch (scope)
            {
            case vsBuildScope.vsBuildScopeSolution:
            case vsBuildScope.vsBuildScopeBatch:
            case vsBuildScope.vsBuildScopeProject:
                BuildScope = (BuildScopes)scope;
                break;

            case 0:
                // Scope may be 0 in case of Clean solution, then Start (F5).
                BuildScope = (BuildScopes)vsBuildScope.vsBuildScopeSolution;
                break;

            default:
                throw new ArgumentOutOfRangeException("scope");
            }

            if (scope == vsBuildScope.vsBuildScopeProject)
            {
                var projContext = _activeProjectContext;
                switch (projContext.Type)
                {
                case vsWindowType.vsWindowTypeSolutionExplorer:
                    ////var solutionExplorer = (UIHierarchy)dte.Windows.Item(Constants.vsext_wk_SProjectWindow).Object;
                    var solutionExplorer = (UIHierarchy)projContext.Object;
                    var items            = (Array)solutionExplorer.SelectedItems;
                    switch (items.Length)
                    {
                    case 0:
                        TraceManager.TraceError("Unable to get target projects in Solution Explorer (vsBuildScope.vsBuildScopeProject)");
                        BuildScopeProject = null;
                        break;

                    case 1:
                        var item = (UIHierarchyItem)items.GetValue(0);

                        var hierachyProjectItem = new ProjectItem();
                        ViewModelHelper.UpdateProperties((Project)item.Object, hierachyProjectItem);
                        BuildScopeProject = hierachyProjectItem;
                        break;

                    default:
                        BuildScopeProject = null;
                        break;
                    }
                    break;

                case vsWindowType.vsWindowTypeDocument:
                    var projectItem = new ProjectItem();
                    ViewModelHelper.UpdateProperties(projContext.Project, projectItem);
                    BuildScopeProject = projectItem;
                    break;

                default:
                    throw new InvalidOperationException("Unsupported type of active project context for vsBuildScope.vsBuildScopeProject.");
                }
            }

            _buildCancelled           = false;
            _buildCancelledInternally = false;

            BuildedProjects.Clear();
            lock (_buildingProjectsLockObject)
            {
                BuildingProjects.Clear();
            }

            BuildedSolution = null;
            var solution = _packageContext.GetDTE().Solution;

            BuildingSolution = new BuildedSolution(solution.FullName, solution.FileName);

            OnBuildBegin(this, EventArgs.Empty);

            _buildProcessCancellationToken = new CancellationTokenSource();
            Task.Factory.StartNew(BuildEvents_BuildInProcess, _buildProcessCancellationToken.Token, _buildProcessCancellationToken.Token);
        }
示例#2
0
        private void BuildEvents_OnBuildBegin(vsBuildScope scope, vsBuildAction action)
        {
            if (action == vsBuildAction.vsBuildActionDeploy)
            {
                return;
            }

            RegisterLogger();

            CurrentBuildState = BuildState.InProgress;

            BuildStartTime  = DateTime.Now;
            BuildFinishTime = null;
            BuildAction     = (BuildActions)action;

            switch (scope)
            {
            case vsBuildScope.vsBuildScopeSolution:
            case vsBuildScope.vsBuildScopeBatch:
            case vsBuildScope.vsBuildScopeProject:
                BuildScope = (BuildScopes)scope;
                break;

            case 0:
                // Scope may be 0 in case of Clean solution, then Start (F5).
                BuildScope = (BuildScopes)vsBuildScope.vsBuildScopeSolution;
                break;

            default:
                throw new ArgumentOutOfRangeException("scope");
            }

            if (scope == vsBuildScope.vsBuildScopeProject)
            {
                var selectedProjects = _packageContext.GetDTE().ActiveSolutionProjects as object[];
                if (selectedProjects?.Length == 1)
                {
                    var projectItem = new ProjectItem();
                    ViewModelHelper.UpdateProperties((Project)selectedProjects[0], projectItem);
                    BuildScopeProject = projectItem;
                }
            }

            _buildCancelled           = false;
            _buildCancelledInternally = false;

            BuildedProjects.Clear();
            lock (_buildingProjectsLockObject)
            {
                BuildingProjects.Clear();
            }

            BuildedSolution = null;
            var solution = _packageContext.GetDTE().Solution;

            BuildingSolution = new BuildedSolution(solution.FullName, solution.FileName);

            OnBuildBegin(this, EventArgs.Empty);

            _buildProcessCancellationToken = new CancellationTokenSource();
            Task.Factory.StartNew(BuildEvents_BuildInProcess, _buildProcessCancellationToken.Token, _buildProcessCancellationToken.Token);
        }