2
votes

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:

  • Include project reference (FruitsComponents => into Project of GardenApp, first added project to Solution)
  • Include DLL alone (FruitsComponents.dll => into Project of GardenApp)

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:

  1. Conflicting assets with the same path '/wwwroot/_framework/de-DE/FruitsComponents.resources.dll' for content root paths 'obj\Debug\net5.0\de-DE\SSW.FruitsComponents.resources.dll' and 'C:\Users\Farmer\Git\FruitsComponents\src\FruitsComponents\bin\Debug\net5.0\de-DE\FruitsComponents.resources.dll'. GardenApp.App.Server C:\Program Files\dotnet\sdk\5.0.101\Sdks\Microsoft.NET.Sdk.Razor\build\netstandard2.0\Microsoft.NET.Sdk.Razor.StaticWebAssets.targets 208

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?

1

1 Answers

2
votes
<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">