Change HostProjectBuildComplete to persist workspace projects.

- This was missed in the VS15.7 movement to dev.
This commit is contained in:
N. Taylor Mullen 2018-03-13 15:11:02 -07:00
parent 1eab654620
commit 492e958114
2 changed files with 37 additions and 5 deletions

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
namespace Microsoft.CodeAnalysis.Razor.ProjectSystem namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
@ -218,9 +219,18 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
if (_projects.TryGetValue(hostProject.FilePath, out var original)) if (_projects.TryGetValue(hostProject.FilePath, out var original))
{ {
var workspaceProject = GetWorkspaceProject(hostProject.FilePath);
if (workspaceProject == null)
{
// Host project was built prior to a workspace project being associated. We have nothing to do without
// a workspace project so we short circuit.
return;
}
// Doing an update to the project should keep computed values, but mark the project as dirty if the // Doing an update to the project should keep computed values, but mark the project as dirty if the
// underlying project is newer. // underlying project is newer.
var snapshot = original.WithHostProject(hostProject); var snapshot = original.WithWorkspaceProject(workspaceProject);
_projects[hostProject.FilePath] = snapshot; _projects[hostProject.FilePath] = snapshot;
// Notify the background worker so it can trigger tag helper discovery. // Notify the background worker so it can trigger tag helper discovery.

View File

@ -72,6 +72,28 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
private Workspace Workspace { get; } private Workspace Workspace { get; }
[ForegroundFact]
public void HostProjectBuildComplete_FindsChangedWorkspaceProject_AndStartsBackgroundWorker()
{
// Arrange
Assert.True(Workspace.TryApplyChanges(WorkspaceProject.Solution));
ProjectManager.HostProjectAdded(HostProject);
var project = WorkspaceProject.WithAssemblyName("Test1"); // Simulate a project change
ProjectManager.WorkspaceProjectAdded(project);
ProjectManager.Reset();
// Act
ProjectManager.HostProjectBuildComplete(HostProject);
// Assert
var snapshot = ProjectManager.GetSnapshot(HostProject);
Assert.True(snapshot.IsDirty);
Assert.True(snapshot.IsInitialized);
Assert.False(ProjectManager.ListenersNotified);
Assert.True(ProjectManager.WorkerStarted);
}
[ForegroundFact] [ForegroundFact]
public void HostProjectAdded_WithoutWorkspaceProject_NotifiesListeners() public void HostProjectAdded_WithoutWorkspaceProject_NotifiesListeners()
{ {
@ -106,7 +128,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
Assert.True(ProjectManager.ListenersNotified); Assert.True(ProjectManager.ListenersNotified);
Assert.True(ProjectManager.WorkerStarted); Assert.True(ProjectManager.WorkerStarted);
} }
[ForegroundFact] [ForegroundFact]
public void HostProjectChanged_WithoutWorkspaceProject_NotifiesListeners_AndDoesNotStartBackgroundWorker() public void HostProjectChanged_WithoutWorkspaceProject_NotifiesListeners_AndDoesNotStartBackgroundWorker()
{ {
@ -396,7 +418,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
// Generate the update // Generate the update
var snapshot = ProjectManager.GetSnapshot(HostProject); var snapshot = ProjectManager.GetSnapshot(HostProject);
var updateContext = snapshot.CreateUpdateContext(); var updateContext = snapshot.CreateUpdateContext();
ProjectManager.HostProjectRemoved(HostProject); ProjectManager.HostProjectRemoved(HostProject);
ProjectManager.Reset(); ProjectManager.Reset();
@ -634,7 +656,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
ProjectManager.HostProjectAdded(HostProject); ProjectManager.HostProjectAdded(HostProject);
ProjectManager.WorkspaceProjectAdded(WorkspaceProject); ProjectManager.WorkspaceProjectAdded(WorkspaceProject);
ProjectManager.Reset(); ProjectManager.Reset();
// Generate the update // Generate the update
var snapshot = ProjectManager.GetSnapshot(HostProject); var snapshot = ProjectManager.GetSnapshot(HostProject);
var updateContext = snapshot.CreateUpdateContext(); var updateContext = snapshot.CreateUpdateContext();
@ -773,7 +795,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem
private class TestProjectSnapshotManager : DefaultProjectSnapshotManager private class TestProjectSnapshotManager : DefaultProjectSnapshotManager
{ {
public TestProjectSnapshotManager(ForegroundDispatcher dispatcher, IEnumerable<ProjectSnapshotChangeTrigger> triggers, Workspace workspace) public TestProjectSnapshotManager(ForegroundDispatcher dispatcher, IEnumerable<ProjectSnapshotChangeTrigger> triggers, Workspace workspace)
: base(dispatcher, Mock.Of<ErrorReporter>(), Mock.Of<ProjectSnapshotWorker>(), triggers, workspace) : base(dispatcher, Mock.Of<ErrorReporter>(), Mock.Of<ProjectSnapshotWorker>(), triggers, workspace)
{ {
} }