Hi, I think my issue was related to the build process. I am building in azure devops and have had to force a VS2022 image, dotnet 6 and vs version 17 in my build yml file. I have documented the changed that worked for me here: blazor-server-net6-razor-class-library-assets-404-error
RCL components not recognised without code behind file
I have a razor class library that I am uplifting to .NET6. The RCL is packaged with nuget and consumed by a blazor server application.
In the RCL I have blazor components (.razor files).
When my components don't have code behind files, they aren't recognised by the code at build time (green squiggly line) and aren't loaded at runtime either.
I have tried using the default namespace from the folder path, and also adding the new @namespace
directive at the top of the file.
Is this intended behaviour?
I am using VS2022.
1 additional answer
Sort by: Most helpful
-
Zhi Lv - MSFT 32,006 Reputation points Microsoft Vendor
2021-11-29T07:24:39.98+00:00 Hi @markcooper ,
When my components don't have code behind files, they aren't recognised by the code at build time (green squiggly line) and aren't loaded at runtime either.
Is this intended behaviour?No, it is not intended behavior. Based on your description, I try to create a new Asp.net 6 Razor class library and the Asp.net 6 Blazor Server application, it works well on my side, no matter the component with or without the background file, I can use the components in the Blazor application.
For your behavior (the component without code-behind file not recognized), I think the problem may be related to the "Build Action" property of the component page, which is set to "None".
To solve this issue, you could right click the component and select the properties option, then set the
Build Action
property toContent
:Then, rebuild the Razor Class Library, and update the Razor class library reference in the Blazor Application.
The result is like below:
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.Best regards,
Dillion