I am trying to create a solution with the standard Blazor server example as one project and a class library as a second project (here it is). The purpose is I want to put a couple of my components up on NuGet for others that might find them useful.
I am struggling with how to tell Visual Studio that the class library has Blazor components. I can't get it to understand that the component.razor.cs file is the code for component.razor.
What do I need to set to make this work?
Update: Following MrC's example I added to the .csproj file:
<ItemGroup>
<SupportedPlatform Include="browser" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="8.0.8" />
</ItemGroup>
But still no luck. If I copy the component to the Blazor server project, it works great (see ExPopupMessageBox in example). But if I use the PopupMessageBox in the library project, I have the problems:
MainLayout.razor shows nothing for (works fine if set to ExPopupMessageBox):
<PopupMessageBox>
<article class="content px-4">
@Body
</article>
</PopupMessageBox>
And the code in the library project must explicitly say it inherits ComponentBase
and the PopupMessageBox.razor.cs file says it is not a partial class definition. So clearly the compiler does not see it as a component.
Take a look at this repository of mine - https://github.com/ShaunCurtis/Blazr.EditStateTracker.
It's the code base for the Blazr.EditStateTracker Nuget package with the build and deploy library and a Blazor Server demo project which is I think is what you're looking for.
Your added description of the problem points to the answer. The compiler doesn't recognise the existence of the Razor files, and therefore doesn't precompile them to C# partial classes.
Your project type is set as a standard class library:
<Project Sdk="Microsoft.NET.Sdk">
It should be set as a Razor class library:
<Project Sdk="Microsoft.NET.Sdk.Razor">