Allow Umbraco projects to work with the Razor cohosting editor#21861
Allow Umbraco projects to work with the Razor cohosting editor#21861davidwengier wants to merge 2 commits intoumbraco:mainfrom
Conversation
|
Hi there @davidwengier, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
There was a problem hiding this comment.
Pull request overview
This pull request adds MSBuild configuration to enable Visual Studio 2026 and VS Code's Razor "cohost" editor to work correctly with Umbraco projects. The Razor cohost editor relies on the Razor source generator for IDE functionality like breakpoints, and requires certain MSBuild items to be configured that are normally provided by Microsoft.NET.Sdk.Web and Microsoft.NET.Sdk.Razor, but not by Umbraco's custom SDK.
Changes:
- Adds design-time build configuration to make .cshtml files visible to the Razor source generator as AdditionalFiles
- Exposes MSBuildProjectDirectory to the compiler for proper path computation
- Includes opt-out mechanism via EnableCohostEditorCompatibility property
src/Umbraco.Cms.Targets/buildTransitive/Umbraco.Cms.Targets.props
Outdated
Show resolved
Hide resolved
src/Umbraco.Cms.Targets/buildTransitive/Umbraco.Cms.Targets.props
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Hello Umbraco friends!
Apologies in advance, for not following good open source practice and just opening a PR blind. Feel free to close it with extreme prejudice, and someone else can post another with the same exact change, I won't mind :)
I work on the Razor tooling team at Microsoft and we have recently shipped a new editor in Visual Studio 2026 and the C# Extension for VS Code, which we refer to as the "cohost" editor. This editor relies on the Razor Source Generator in order to function, and unfortunately, we've had reports from some of our users, who are also your users, that breakpoints and other IDE functionality doesn't work in their projects any more. The root cause of this is that there are some things done in the Microsoft.NET.Sdk.Web and Microsoft.NET.Sdk.Razor SDKs that the IDE relies on, that are not done in your SDK.
This PR represents a polyfill to bridge that gap, and allow your users to continue to be our users, and have the full IDE functionality they expect. I am certainly not an Umbraco expert (or beginner!), so please let me know if this change needs to go somewhere else, but we have had confirmation that putting this little bit of MSBuild goo in a project file successfully unblocks people.
Issues that have been filed against us (hopefully in lieu of this PR resolving any specific issue on this repo):
https://developercommunity.visualstudio.com/t/Breakpoints-is-not-working-in-Razor-file/10978894
https://developercommunity.visualstudio.com/t/A-breakpoint-could-not-be-inserted-at-t/11047278 (with confirmation that the change works)
Fixes dotnet/razor#12331 (which is the first issue above, moved to our GitHub repo)
Thanks!
Dave