Reputation: 581
I'm currently working on a .NET 5.0 Blazor WebAssembly application.
I use a Blazor Component library, which I want to add to my Project solution as a reference.
My project structure looks like this:
1. GardenApp:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<TargetFramework>net5.0</TargetFramework>
2. FruitsComponents:
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
<TargetFramework>net5.0</TargetFramework>
When I reference my FruitsComponents library as a NuGet package in my GardenApp it works fine, but when I try to reference the FruitsComponents library as a project in my GardenApp.
I already tried in vain:
I get the following errors:
1) MSB4018 The "GenerateServiceWorkerAssetsManifest" task failed unexpectedly.
System.AggregateException: One or more errors occurred. ---> System.IO.FileNotFoundException: Could not find file 'C:\Users\Farmer\Git\GardenApp\src\GardenApp\Client\obj\Debug\net5.0\FruitsComponents.pdb'.
and the second Error:
Do you know how to reference a component library of type Microsoft.NET.Sdk.BlazorWebAssembly in a Blazor project of type Microsoft.NET.Sdk.BlazorWebAssembly - or any other ideas on how to solve this issue?
Upvotes: 2
Views: 852
Reputation: 273464
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
is correct for the main project, the App. It is the wrong project type for a Component, thus the 'duplicate' errors. You are trying to link an App to an App.
A Blazor Component project is called a Razor ClassLibrary. You make it suitable for Blazor by not checking the Pages & Views option in VS. The sdk line should read:
2. FruitsComponents:
<Project Sdk="Microsoft.NET.Sdk.Razor">
Upvotes: 3