Search code examples
c#visual-studioblazor-webassembly.net-6.0

Build Error with External Assembly in .NET6 Blazor Webassembly App


I'm trying to create Blazor Webassembly App with .Net6 using Visual Studio 2022(preview). And I've referenced external assembly file in that project. When I build the project, I got the following error,

The asset 'D:\Office\Testing\BlazorApp1\BlazorApp1\bin\Debug\net6.0\wwwroot_framework\ClassLibrary1.dll' can not be found at any of the searched locations 'D:\Office\Testing\BlazorApp1\BlazorApp1\bin\Debug\net6.0\wwwroot_framework\ClassLibrary1.dll' and 'ClassLibrary1'

screen shot image

Is there a solution for that ?

Project's Properties here

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <ServiceWorkerAssetsManifest>service-worker-assets.js</ServiceWorkerAssetsManifest>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0-rc.1.21452.15" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0-rc.1.21452.15" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="ClassLibrary1">
      <HintPath>Lib\ClassLibrary1.dll</HintPath>
      <EmbedInteropTypes></EmbedInteropTypes>
    </Reference>
  </ItemGroup>

  <ItemGroup>
    <ServiceWorker Include="wwwroot\service-worker.js" PublishedContent="wwwroot\service-worker.published.js" />
  </ItemGroup>

</Project>

Solution

  • You just need to change this,

    <ItemGroup>
       <Reference Include="../Lib/ClassLibrary1">
         <HintPath>Lib\ClassLibrary1.dll</HintPath>
         <EmbedInteropTypes></EmbedInteropTypes>
       </Reference>   
    </ItemGroup>