internal Task HandleEndBuildAsync(BuildEventArgs args)
        {
            if (!args.Success)
            {
                // Build failed
                return(Task.CompletedTask);
            }

            return(_projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync((projectItem, ct) =>
            {
                if (!_projectService.IsSupportedProject(projectItem))
                {
                    // We're hooked into all build events, it's possible to get called with an unsupported project item type.
                    return;
                }

                var projectPath = _projectService.GetProjectPath(projectItem);
                var projectSnapshot = _projectManager.GetLoadedProject(projectPath);
                if (projectSnapshot != null)
                {
                    var workspaceProject = _projectManager.Workspace.CurrentSolution?.Projects.FirstOrDefault(
                        project => FilePathComparer.Instance.Equals(project.FilePath, projectSnapshot.FilePath));
                    if (workspaceProject != null)
                    {
                        // Trigger a tag helper update by forcing the project manager to see the workspace Project
                        // from the current solution.
                        _workspaceStateGenerator.Update(workspaceProject, projectSnapshot, CancellationToken.None);
                    }
                }
            }, args.SolutionItem, CancellationToken.None));
        }
Exemple #2
0
        // Internal for testing
        internal void UpdateRazorHostProject()
        {
            _foregroundDispatcher.AssertForegroundThread();

            DetachCurrentRazorProjectHost();

            if (!_projectService.IsSupportedProject(_project))
            {
                // Not a Razor compatible project.
                return;
            }

            if (!TryGetProjectSnapshotManager(out var projectSnapshotManager))
            {
                // Could not get a ProjectSnapshotManager for the current project.
                return;
            }

            if (_project.IsCapabilityMatch(ExplicitRazorConfigurationCapability))
            {
                // SDK >= 2.1
                _razorProjectHost = new DefaultRazorProjectHost(_project, _foregroundDispatcher, projectSnapshotManager);
                return;
            }

            // We're an older version of Razor at this point, SDK < 2.1
            _razorProjectHost = new FallbackRazorProjectHost(_project, _foregroundDispatcher, projectSnapshotManager);
        }
        // Internal for testing
        internal void UpdateRazorHostProject()
        {
            _ = _projectSnapshotManagerDispatcher.RunOnDispatcherThreadAsync(() =>
            {
                DetachCurrentRazorProjectHost();

                if (!_projectService.IsSupportedProject(_project))
                {
                    // Not a Razor compatible project.
                    return;
                }

                if (!TryGetProjectSnapshotManager(out var projectSnapshotManager))
                {
                    // Could not get a ProjectSnapshotManager for the current project.
                    return;
                }

                if (_project.IsCapabilityMatch(ExplicitRazorConfigurationCapability))
                {
                    // SDK >= 2.1
                    _razorProjectHost = new DefaultRazorProjectHost(_project, _projectSnapshotManagerDispatcher, projectSnapshotManager);
                    return;
                }

                // We're an older version of Razor at this point, SDK < 2.1
                _razorProjectHost = new FallbackRazorProjectHost(_project, _projectSnapshotManagerDispatcher, projectSnapshotManager);
            }, CancellationToken.None);
        }
        // Internal for testing
        internal void ProjectOperations_EndBuild(object sender, BuildEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            _foregroundDispatcher.AssertForegroundThread();

            if (!args.Success)
            {
                // Build failed
                return;
            }

            var projectItem = args.SolutionItem;

            if (!_projectService.IsSupportedProject(projectItem))
            {
                // We're hooked into all build events, it's possible to get called with an unsupported project item type.
                return;
            }

            var projectPath = _projectService.GetProjectPath(projectItem);

            // Get the corresponding roslyn project by matching the project name and the project path.
            foreach (var projectSnapshot in _projectManager.Projects)
            {
                if (string.Equals(projectPath, projectSnapshot.FilePath, StringComparison.OrdinalIgnoreCase))
                {
                    _projectManager.HostProjectBuildComplete(projectSnapshot.HostProject);
                    break;
                }
            }
        }
        // Internal for testing
        internal void ProjectOperations_EndBuild(object sender, BuildEventArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            _foregroundDispatcher.AssertForegroundThread();

            if (!args.Success)
            {
                // Build failed
                return;
            }

            var projectItem = args.SolutionItem;

            if (!_projectService.IsSupportedProject(projectItem))
            {
                // We're hooked into all build events, it's possible to get called with an unsupported project item type.
                return;
            }

            var projectPath     = _projectService.GetProjectPath(projectItem);
            var projectSnapshot = _projectManager.GetLoadedProject(projectPath);

            if (projectSnapshot != null)
            {
                var workspaceProject = _projectManager.Workspace.CurrentSolution?.Projects.FirstOrDefault(
                    project => FilePathComparer.Instance.Equals(project.FilePath, projectSnapshot.FilePath));
                if (workspaceProject != null)
                {
                    // Trigger a tag helper update by forcing the project manager to see the workspace Project
                    // from the current solution.
                    _workspaceStateGenerator.Update(workspaceProject, projectSnapshot);
                }
            }
        }