Reputation: 61
I have a problem, and I can't find a solution. This question is maybe already solved a couple of times, but it's hard to find a working solution for my constellation.
I'm using Blazor wasm 3.2.0-preview3.20168.3'. My goal is to move my components in a shared library to use it across my projects.
The problem is my components are not going to be rendered if I'm moving them into a shared library, so the tag <alert><alert/>
is not resolved. The browser displays <alert><alert/>
.
If they are in the main project, everything is working fine.
In the main project in "_Imports.razor" the dependencies are imported
@using BlazingWebShared.Services
@using BlazingWebShared.Component
My library .csproj
looks more or less like this (not including comments etc):
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.0-preview3.20168.3" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.0-preview3.20168.3" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.2.0-preview3.20168.3" />
</ItemGroup>
</Project>
Does someone have an idea what I'm doing wrong? Or can someone share a library I can use as a blueprint?
Thank you very much for your time and help.
Upvotes: 1
Views: 1066
Reputation: 273264
The line
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
tells me that you checked "support for pages and views" when you created your Razor Class Library (RCL). Make a new one without that check. You get a very different project setup with or without that checkmark. Amongst other things it will target the wrong platform, core 3.x instead of standard 2.x
And don't forget that you also have to import the .css and maybe .js files from the RCL into your _Host.razor or Index.cshtml . See this answer for that.
Upvotes: 1