aspnetcore: View component not being rendered using tag helper syntax
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I am trying to use a view component using the tag helper syntax <vc:[view-component-name]> and since the latest .NET release (7.0.200) it is not being rendered if I run my published application in Linux, instead I am seeing the <vc:[view-component-name]> markup in the HTML being sent to the client.
Expected Behavior
I expect the tag helper to work as expected and invoke the view component, not render the raw markup from the cshtml-file.
Steps To Reproduce
- Create ASP.NET project using .NET 7.0.200 on Linux
- Add a view component
- Render it using the tag helper syntax
- Publish the project
dotnet publish - Run the project
./Project
Exceptions (if any)
I am not getting any error messages or exceptions.
.NET Version
7.0.200
Anything else?
Things I have tried:
- It works fine when I use
dotnet runon both Linux and Windows - It works fine when I publish on Windows using
dotnet publish - It does not work in Linux when using
dotnet publish await Component.InvokeAsyncworks as expected- It was working fine with the last .NET release before 7.0.200
Read the comments, other users have reported the same problem in many more cases.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 20
- Comments: 32 (1 by maintainers)
Rendering of view components using tag helpers is broken with the release of the new SDKs of 2023-02-14. I believe this is the versions where this is broken:
It is not related to Linux. Not even specifically to Visual Studio.
We see the razor syntax in our HTML like this:
<vc:hero-image></vc:hero-image>Noticed this last week already and (like already suggested) pinned to a lower SDK version using global.json(@DavidZidar Thanks for changing the title, was just going to suggest that)
(edited to add SDK versions)
This is definitely an SDK issue with 7.0.200. It seems that the latest SDK available on your machine will be used by default. Meaning that even if your project is targeting .NET 6, the v7 SDK will be used if available.
You can use a
global.jsonfile to pin the build to a specific SDK version. Add the file next to your solution file with these contents:We use Azure DevOps to perform our builds and use the
UseDotNettask to specify which version of the SDK to use for the builds (this needs to happen before any building/restoring/etc.):Alternatively, you can convert all the ViewComponent tag helpers in your project(s) to use the
@await Component.InvokeAsync(...)method instead.I have the same issue but I’m not publishing, I am just running in development using
dotnet runEarlier tonight I upgraded Visual Studio to 17.5 (from 17.4 if memory is correct…) Prior to the update the view component tag-helper syntax worked as expected. Afterwards, only seems to work if I use Component.InvokeAsync() syntax.
I’m only 1 developer working on my local development machine (Windows 11).
Following SDKS now installed after VS upgrade:
Here’s a quick rundown of the setup for this simple VC:
PROJECT TARGET SDK:
<TargetFramework>net7.0</TargetFramework><PROJECTDIR>/Views/_ViewImports.cshtml: (some usings removed for brevity)
<PROJECTDIR>/ViewComponents/WorkspaceSelector.cs:
<PROJECTDIR>/Views/Shared/Components/WorkspaceSelector/Default.cshtml: …contains the view code for the component
<PROJECTDIR>/Views/Personnel/Index.cshtml (the view where I use the view component):
Hope this was helpful. If not, just delete/cancel me. 😃
Ok, good, that does sound like either the same or a related issue. In my case it only breaks when I publish and then run the published application and only in Linux.
They are correct, the app works as intended (renders vc tag helpers) in a Windows Sandbox environment with an older .NET SDK
Probably not until the release in March (2-3 weeks from now). They released a small update for the SDK a few days ago (7.0.201) without fixing this and I doubt that they will do another extra release before the next regular one.
Adding the
global.jsonworked for me. This threw me for a loop because I thought the upgrade to the newest version of Visual Studio caused it. But then downgrading did not help.This should be a SDK issue as I am using SDK to build and publish not Visual Studio
They are aware of the issue and are working on getting a fix out. https://github.com/dotnet/razor/issues/8281#issuecomment-1446996618
Same happened for us too (our existing project VC rendering stopped working)
Looking further into this, it appears that if you pin yourself to
6.0.404you are ok, but if compiling against6.0.406it fails as outlined as wellI have detailed logs from a build & unit test that fails in this transition
I’m facing same issue with SDK 7.0.200. Also same as https://github.com/dotnet/razor/issues/8281 It’s horrible issue because no error and warning at build.
I have rewrote <vc: to @await Component.InvokeAsync as workaround.
Can confirm the same issue started after updating Visual Studio 17.5, even without updating packages.
I have the same problem. But I’m publishing to a Windows Web App in Azure. However, I am using a linux build agent in Azure DevOps. There is a StackOverflow question for this as well.
I have the same problem when publishing the application in a Linux Web App in Azure.
I am publishing the application using Azure DevOps using a linux vm.
The View Components are not rendered using a Tag Helper … Only using
Component.InvokeAsync.In my computer, a MAC, it works both. using a Tag Helper or
Component.InvokeAsync