Skip to content

Fix razor generator/ed files not appearing in solution explorer - #85673

Merged
davidwengier merged 4 commits into
dotnet:mainfrom
davidwengier:fix-razor-generator-solution-explorer
Sep 22, 2026
Merged

davidwengier merged 4 commits into
dotnet:mainfrom
davidwengier:fix-razor-generator-solution-explorer

Conversation

@davidwengier

@davidwengier davidwengier commented Sep 16, 2026 •

Copy link
Copy Markdown
Member

Fixes #79052

Looks like:
image

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 16, 2026 05:37
@davidwengier
davidwengier requested a review from a team as a code owner September 16, 2026 05:37
@davidwengier
davidwengier requested a review from a team September 16, 2026 05:37
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

internal bool IsPrimaryProject(ProjectId projectId)
=> GetProjectSystemProject(projectId)?.IsPrimary ?? true;

internal string? TryRedirectAnalyzerAssembly(ProjectId projectId, string fullPath)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed based on the existing code that exposing the ProjectSystemProject from a method would be undesirable, but let me know if that's not the correct call, and I could move this and IsPrimaryProject to their call sites, and make the API of this class a little less big-grab-bag-of-stuff.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Final human review is recommended for the cross-component Solution Explorer and Razor redirection changes.

Pull request overview

Fixes Razor source generators not appearing in Solution Explorer by applying analyzer redirection during CPS lookup and handling case differences.

Changes:

  • Routes analyzer redirection through the workspace and CPS lookup.
  • Makes Razor assembly mapping case-insensitive.
  • Adds regression tests.
File summaries
File Summary
src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProject.cs Exposes analyzer redirection.
src/VisualStudio/Core/Test/SolutionExplorer/CpsDiagnosticItemSourceTests.vb Tests redirected generator discovery.
src/VisualStudio/Core/Impl/SolutionExplorer/DiagnosticItem/CpsDiagnosticItemSourceProvider.cs Bridges CPS lookup to the workspace implementation.
src/VisualStudio/Core/Impl/SolutionExplorer/DiagnosticItem/CpsDiagnosticItemSource.cs Redirects paths before reference lookup.
src/VisualStudio/Core/Def/ProjectSystem/VisualStudioWorkspaceImpl.cs Provides the project-system redirection bridge.
src/Razor/src/Razor/test/Microsoft.VisualStudio.LanguageServices.Razor.UnitTests/AssemblyRedirectorTests.cs Tests case-insensitive matching.
src/Razor/src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/RazorAnalyzerAssemblyRedirector.cs Handles lowercase CPS paths.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 0
  • Review effort level: Lite

@jasonmalinowski jasonmalinowski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the high level is fine, but I worry we introduced a potential race moving use of the ProjectSystemProject out of the lock. I think the method we were trying to call is just movable though, so should be an easy fix up.

Comment on lines +61 to +63
// CPS canonicalizes analyzer paths to lowercase, so match assembly names case-insensitively, otherwise the source
// generator doesn't show up in the Dependencies node in Visual Studio.
return compilerAssemblyTypes.ToFrozenDictionary(t => t.name, t => t.path, StringComparer.OrdinalIgnoreCase);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, did this mean we generally weren't redirecting?

@davidwengier davidwengier Sep 17, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested, but I could imagine its possible if someone manually referenced the Razor compiler but didn't match the casing in the msbuild include, then we might not redirect it. Of course, if someone manually referenced the Razor compiler, they're already out in no mans land, and how knows if they expect or get IDE support. We haven't had any issues that indicate anyone has done that.

Copilot AI review requested due to automatic review settings September 17, 2026 22:59
@davidwengier

Copy link
Copy Markdown
Member Author

Pushed changes to address the comments, thanks. I ended up sticking with a static class, as getting at the host info for an extension method, only to use a single property, made for a lot more spaghetti than I'd like. Let me know if you feel strongly though.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The changes include regression coverage and have no unresolved blocking issues.

Review details
  • Files reviewed: 10/10 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@davidwengier
davidwengier requested a review from a team September 21, 2026 05:21
@davidwengier
davidwengier merged commit 97b4837 into dotnet:main Sep 22, 2026
23 checks passed
@davidwengier
davidwengier deleted the fix-razor-generator-solution-explorer branch September 22, 2026 10:29
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Sep 22, 2026
@jjonescz jjonescz modified the milestones: Next, 18.12 Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Razor generated files don't appear in Solution Explorer

4 participants