Search code examples
c#asp.net-coreblazordotnet-cli

Blazor Web App & dotnet publish - Conflicting assets with the same target path


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 'solution\Web\Web.csproj' --no-restore --runtime:win-x64 --output:publish/Web --configuration:Local
C:\Program Files\dotnet\sdk\8.0.301\Sdks\Microsoft.NET.Sdk.StaticWebAssets\targets\Microsoft.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: solution\Web.Admin.Client\obj\Local\net8.0\compressed\publish\0pitllaw99.br
SourceType: Project
SourceId: Web.Admin.Client
ContentRoot: solution\publish\Web\wwwroot\
BasePath: Web.Admin.Client
RelativePath: _framework/Microsoft.EntityFrameworkCore.Relational.wasm.br
AssetKind: Publish
AssetMode: All
AssetRole: Alternative
AssetRole: 
AssetRole: 
RelatedAsset: solution\Web.Admin.Client\obj\Local\net8.0\webcil\publish\Microsoft.EntityFrameworkCore.Relational.wasm
AssetTraitName: Content-Encoding
AssetTraitValue: br
CopyToOutputDirectory: Never
CopyToPublishDirectory: PreserveNewest
OriginalItemSpec: solution\Web.Admin.Client\obj\Local\net8.0\webcil\publish\Microsoft.EntityFrameworkCore.Relational.wasm' 

and

'Identity: solution\Web.Client\obj\Local\net8.0\compressed\publish\ekk7igjstw.br
SourceType: Project
SourceId: Web.Admin.Client
ContentRoot: solution\publish\Web\wwwroot\
BasePath: Web.Admin.Client
RelativePath: _framework/Microsoft.FEntityFrameworkCore.Relational.wasm.br
AssetKind: Publish
AssetMode: All
AssetRole: Alternative
AssetRole: 
AssetRole: 
RelatedAsset: solution\Web.Client\obj\Local\net8.0\webcil\publish\Microsoft.EntityFrameworkCore.Relational.wasm
AssetTraitName: Content-Encoding
AssetTraitValue: br
CopyToOutputDirectory: Never
CopyToPublishDirectory: PreserveNewest
OriginalItemSpec: solution\Web.Client\obj\Local\net8.0\webcil\publish\Microsoft.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.Models\Domain.Data.Models.csproj" />
    <ProjectReference Include="..\Domain\Domain.csproj" />
    <ProjectReference Include="..\Infrastructure.Client\Infrastructure.Client.csproj" />
    <ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />

    <ProjectReference Include="..\Web.Client\Web.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.Components\Web.Shared.Components.csproj" />
    <ProjectReference Include="..\Web.Admin.Client\Web.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.Components\Web.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.


Solution

  • 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.