Fix a bug in tag helper discovery on build

This commit is contained in:
Ryan Nowak 2018-02-20 13:07:01 -08:00
parent 0b777dad3f
commit cf5743ea86
2 changed files with 14 additions and 1 deletions

View File

@ -49,6 +49,19 @@ namespace Microsoft.VisualStudio.LanguageServices.Razor
return Task.FromResult(TagHelperResolutionResult.Empty);
}
// In 15.6-7 this API is called by WTE to resolve tag helpers, and can be called on build - ie: without any ProjectSnapshot
// changes. That means that projectSnapshot.WorkspaceProject is out of date with respect to the actual workspace.
//
// To work around this issue, always grab the latest WorkspaceProject with the same ID, which will trigger tag helper
// discovery on the current state of the workspace.
//
// This workaround won't be needed in 15.8 since we do tag helper discovery through the project snapshot manager.
var latest = _workspace.CurrentSolution.GetProject(projectSnapshot.WorkspaceProject.Id) ?? projectSnapshot.WorkspaceProject;
if (projectSnapshot.WorkspaceProject != latest)
{
projectSnapshot = ((DefaultProjectSnapshot)projectSnapshot).WithWorkspaceProject(latest);
}
var resolver = _workspace.Services.GetLanguageServices(RazorLanguage.Name).GetRequiredService<TagHelperResolver>();
return resolver.GetTagHelpersAsync(projectSnapshot);
}

View File

@ -177,7 +177,7 @@ namespace Microsoft.CodeAnalysis.Razor.ProjectSystem.Rules {
Microsoft.Build.Framework.XamlTypes.Rule t = ((Microsoft.Build.Framework.XamlTypes.Rule)(ruleEnumerator.Current));
if (System.StringComparer.OrdinalIgnoreCase.Equals(t.Name, SchemaName)) {
unboundRule = t;
unboundRule.Name = "843bc0bc-5265-4864-9b06-f5d5503b0484";
unboundRule.Name = "6ffb2641-19cd-4943-bc6d-446919acb77e";
RazorConfiguration.deserializedFallbackRule = unboundRule;
}
}