Skip to content

Conversation

@drewnoakes
Copy link
Member

The Razor Class Library template has an option, SupportsPagesAndViews that causes it to produce one of two sets of files. If true, then Areas/MyFeature/Pages/Page1.cshtml is created. If false, then Component1.razor is created.

The issue with the previous template is that the set of primary outputs and the corresponding openInEditor post-actions were not taking this option into account, and were always trying to open the Page1.cshtml file, even if it didn't exist on disk.

This led to the bug described in microsoft/vscode-dotnettools#2489

C# Dev Kit has been patched to not show warnings when a template specifies that non-existent files should be opened.

With the change here, users creating this template will now see the correct file opened. This applies both to VS and CDK.

The Razor Class Library template has an option, `SupportsPagesAndViews`
that causes it to produce one of two sets of files. If true, then
`Areas/MyFeature/Pages/Page1.cshtml` is created. If false, then
`Component1.razor` is created.

The issue with the previous template is that the set of primary outputs
and the corresponding `openInEditor` post-actions were not taking this
option into account, and were always trying to open the `Page1.cshtml`
file, even if it didn't exist on disk.

This led to the bug described in microsoft/vscode-dotnettools#2489

C# Dev Kit has been patched to not show warnings when a template
specifies that non-existent files should be opened.

With the change here, users creating this template will now see the
correct file opened. This applies both to VS and CDK.
Copilot finished reviewing on behalf of drewnoakes November 26, 2025 02:53
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug in the Razor Class Library template where post-actions were attempting to open files that didn't exist. The template supports two modes controlled by the SupportPagesAndViews parameter: when true, it creates Areas/MyFeature/Pages/Page1.cshtml; when false, it creates Component1.razor. Previously, the template always tried to open Page1.cshtml regardless of which mode was used.

Key changes:

  • Added conditional logic to primaryOutputs to specify the correct file based on SupportPagesAndViews parameter
  • Added a new openInEditor post-action for the Component1.razor file with appropriate conditions
  • Updated the existing openInEditor post-action for Page1.cshtml to only apply when SupportPagesAndViews is true

@drewnoakes
Copy link
Member Author

I can't see how the pipeline failures are related to this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-blazor-template-engine feature-templates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants