skip to Main Content

I am experiencing an error with dotnet publish – this does not occur during build. I understand the problem – two projects are copying files to the same place in the output. What I don’t understand is the fix. I have a dotnet 8 Blazor web app consisting of several projects (hierarchy shows dependency chain) –

  • Web (<Project Sdk="Microsoft.NET.Sdk.Web">) <— the artifact being published
    • Web.Client (<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">) <– one of the offenders
      • Web.Admin.Client (<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">) <– one of the offenders
      • Web.Admin.Shared (<Project Sdk="Microsoft.NET.Sdk.Razor">)
      • Web.ABC.Client (<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">) (there are several of these)
      • ApplicationClassLib (<Project Sdk="Microsoft.NET.Sdk">).
  • Web.Admin (<Project Sdk="Microsoft.NET.Sdk.Web">) (Deployment Artifact)
  • Web.ABC (<Project Sdk="Microsoft.NET.Sdk.Web">) (Another Deployment Artifact)

I have added ErrorOnDuplicatePublishOutputFiles to Web.Client and I have added the following properties to Web.Admin.Client. I encountered this error before and adding StaticWebAssetBasePath to each of the Web.*.Client apps fixed it then. I have deleted obj and bin folders from every project and restarted Visual Studio as well. I even updated dotnet and the whole tool chain (including Visual Studio) just in case. I need the dependencies to be available at runtime – I’m not sure if removing the file from the output is the correct direction.

The publish command – note that Visual Studio’s publish fails with the same (or very similar) error.

 dotnet publish 'solutionWebWeb.csproj' --no-restore --runtime:win-x64 --output:publish/Web --configuration:Local
C:Program Filesdotnetsdk8.0.301SdksMicrosoft.NET.Sdk.StaticWebAssetstargetsMicrosoft.NET.Sdk.StaticWebAssets.Publish.targets(25,5): error : 

Conflicting assets with the same target path 
'Web.Admin.Client/_framework/Microsoft.EntityFrameworkCore.Relational.wasm.br'. 
For 'Publish' assets 'Identity: solutionWeb.Admin.ClientobjLocalnet8.0compressedpublishpitllaw99.br
SourceType: Project
SourceId: Web.Admin.Client
ContentRoot: solutionpublishWebwwwroot
BasePath: Web.Admin.Client
RelativePath: _framework/Microsoft.EntityFrameworkCore.Relational.wasm.br
AssetKind: Publish
AssetMode: All
AssetRole: Alternative
AssetRole: 
AssetRole: 
RelatedAsset: solutionWeb.Admin.ClientobjLocalnet8.0webcilpublishMicrosoft.EntityFrameworkCore.Relational.wasm
AssetTraitName: Content-Encoding
AssetTraitValue: br
CopyToOutputDirectory: Never
CopyToPublishDirectory: PreserveNewest
OriginalItemSpec: solutionWeb.Admin.ClientobjLocalnet8.0webcilpublishMicrosoft.EntityFrameworkCore.Relational.wasm' 

and

'Identity: solutionWeb.ClientobjLocalnet8.0compressedpublishekk7igjstw.br
SourceType: Project
SourceId: Web.Admin.Client
ContentRoot: solutionpublishWebwwwroot
BasePath: Web.Admin.Client
RelativePath: _framework/Microsoft.FEntityFrameworkCore.Relational.wasm.br
AssetKind: Publish
AssetMode: All
AssetRole: Alternative
AssetRole: 
AssetRole: 
RelatedAsset: solutionWeb.ClientobjLocalnet8.0webcilpublishMicrosoft.EntityFrameworkCore.Relational.wasm
AssetTraitName: Content-Encoding
AssetTraitValue: br
CopyToOutputDirectory: Never
CopyToPublishDirectory: PreserveNewest
OriginalItemSpec: solutionWeb.ClientobjLocalnet8.0webcilpublishMicrosoft.EntityFrameworkCore.Relational.wasm'.

Web is the root host for all of the web interface and components.

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <RuntimeIdentifiers>win-x64;linux-x64;linux-arm64</RuntimeIdentifiers>
    <Configurations>Debug;Release;Local</Configurations>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <RootNamespace>Web</RootNamespace>
    <AssemblyName>Web</AssemblyName>
    <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
  </PropertyGroup>
  
  
  <ItemGroup>
<!-- All four of these are Class Libraries -->
    <ProjectReference Include="..Domain.Data.ModelsDomain.Data.Models.csproj" />
    <ProjectReference Include="..DomainDomain.csproj" />
    <ProjectReference Include="..Infrastructure.ClientInfrastructure.Client.csproj" />
    <ProjectReference Include="..InfrastructureInfrastructure.csproj" />

    <ProjectReference Include="..Web.ClientWeb.Client.csproj" />
   
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.6" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.6" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>
</Project>

Web.Client is the WASM side and is where the components are brought into the app.

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <RuntimeIdentifiers>win-x64;linux-x64;linux-arm64;</RuntimeIdentifiers>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>

    <RootNamespace>Web.Client</RootNamespace>
    <AssemblyName>Web.Client</AssemblyName>

    <Configurations>Debug;Release;Local</Configurations>
    <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.6" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..Web.Shared.ComponentsWeb.Shared.Components.csproj" />
    <ProjectReference Include="..Web.Admin.ClientWeb.Admin.Client.csproj" />

  </ItemGroup>
</Project>

Web.Admin is used to house a Web Api – nothing more or less.

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

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>

    <RuntimeIdentifiers>win-x64;linux-x64;linux-arm64</RuntimeIdentifiers>
    <Configurations>Debug;Release;Local</Configurations>

    <AssemblyName>Web.Admin</AssemblyName>
    <RootNamespace>Web.Admin</RootNamespace>
  </PropertyGroup>

  <ItemGroup
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.6" />
  </ItemGroup>
</Project>

Web.Admin.Client houses admin related WASM components imported and used by Web.Client

<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <NoDefaultLaunchSettingsFile>true</NoDefaultLaunchSettingsFile>
   
    <AssemblyName>Web.Admin.Client</AssemblyName>
    <RootNamespace>Web.Admin.Client</RootNamespace>
    
    <StaticWebAssetBasePath>Web.Admin.Client</StaticWebAssetBasePath>
    <ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.6" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.6" />
    
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.6" />
    <PackageReference Include="Microsoft.Extensions.Identity.Core" Version="8.0.6" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..Web.Shared.ComponentsWeb.Shared.Components.csproj" />
  </ItemGroup>
</Project>

Microsoft.EntityFrameworkCore.Relational is referenced in only 2 places (Domain and Infrastructure) which are both Class Libraries and both only referenced in Web – not Web.Client or Web.Admin.Client

I am working to create a minimum reproducible example but as of yet have not succeeded — I am very confused and going bald. Thank you in advance for any and all help — it is appreciated.

Update:

Whatever the issue is it has something to do with Blazor Web Assembly apps being ProjectReferenced into other Blazor Web Assembly app while also referencing the same packages maybe directly or transitively. I reverted changes back to a known good state and followed my changes through to discover that when the project reference for Web.Admin.Client is added to Web.Client this starts happening. I also discovered that Web.Admin.Client is referencing Microsoft.EntityFrameworkCore.Relational as a transitive dependency through Microsoft.AspNetCore.Identity.EntityFrameworkCore which Web also references. After discovering that, I then removed Admin stuff entirely (by moving its code into Web) and encountered the same error but for System.Runtime.wasm.br from a different Blazor Web Assembly project. These changes were made because I had to move Routes.razor from Web into Web.Client – which has to import the rest of the Client projects via AdditionalAssemblies.

2

Answers


  1. Chosen as BEST ANSWER

    So after researching and hunting I discovered that what I'm trying to do isn't supported by the framework - specifically referencing/using a Blazor Web Assembly in another Blazor Web Assembly app is unsupported.

    The workaround for me was to move the Admin.Client code into a Razor Class Library.


  2. The root cause of your issue is that both Web.Client and Web.Admin.Client projects include Microsoft.EntityFrameworkCore.Relational.wasm.br in their output, leading to a conflict when publishing. This is likely because both projects directly or indirectly reference a project that includes Entity Framework Core.

    Some possible solutions:

    • Centralize EF Core reference:

    •Option A: Move the Entity Framework Core package reference to the Web project, ensuring it is only referenced once in the entire solution. This centralizes the dependency and avoids the conflict.

    • Option B: If the EF Core dependency is genuinely needed in both client projects, create a shared class library project specifically for data access. Reference this new project from both Web.Client and Web.Admin.Client.

    • Exclude conflicting assets:

    • In the Web.Client and Web.Admin.Client projects, add explicit exclusions for the conflicting assets in the .csproj file:

    <ItemGroup>
      <Content Remove="_framework/Microsoft.EntityFrameworkCore.Relational.wasm.br" />
    </ItemGroup>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search