How to move blazor components to a different assembly

Viewed 706

I have a blazor server project, and I wanted to move some of the shared components to a different assembly to see if it would make a difference in the compilation times (bonus for letting me know if this would work...), but this isn't going so well.

In VS2019 the razor.cs parts of the components are at the same level as the .razor parts (rather than being 'under' them as they are in the blazor project), and other components can't find them. Oddly the project builds and runs, but the components are just drawn blank. I've cleaned, rebuilt, deleted the bin and obj folders, restarted VS etc, and no changes.

I have updated the _Imports.razor file, and everything should be as it needs to be, but this just isn't working.

Any help appreciated!

EDIT: This is 'Under':

enter image description here

And this is how it's displaying: enter image description here

3 Answers

How to move blazor components to a different assembly ?

You can change the namespace using @namespace Your.Name.Space

Oddly the project builds and runs, but the components are just drawn blank.

Only the .cs base part is gettting linked in, your .razor code is ignored. So all your components render as their base class, empty.

You need build-time support for compiling the .razor to intermediate C#.

You can move the pages to a Razor Class Library, and then do not check the 'suport pages and views' box.

But that project type is more aimed at independent components, providing their own css files etc. That may or not suit your needs.

In general I wouldn't expect much difference in build times, they could even go up. So you may want to reconsider this.

In my silliest case ever the .razor file had a Build Action set to None instead of Content

Related