【问题标题】:dotnet publish of a Blazor WASM project errors with An item with the same key has already been addedBlazor WASM 项目的 dotnet 发布错误,已添加具有相同密钥的项目
【发布时间】:2021-11-02 23:01:36
【问题描述】:

在发布使用 .NET 6 的 Blazor WASM 项目时遇到了问题。

以前,它在 .NET 5 上,构建/发布应用程序没有问题。

我已将其更新为 .NET 6,主要是更新以下 nuget 引用:

  • Microsoft.AspNetCore.Components.WebAssembly(转至6.0.0-rc.2.21480.10
  • Microsoft.AspNetCore.Components.WebAssembly.DevServer(转至6.0.0-rc.2.21480.10

由于DynamicComponent 的要求,我们已更新到 .NET 6

在开发过程中本地运行没问题。

在我们的构建管道期间,我正在执行以下操作来发布应用程序:

dotnet publish .\Web\Web.Connect --configuration debug --output output

我得到的输出是:

  Web.Connect -> C:\git\core\Web\Web.Connect\bin\debug\net6.0\Web.Connect.dll
  Web.Connect (Blazor output) -> C:\git\core\Web\Web.Connect\bin\debug\net6.0\wwwroot
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error : System.ArgumentException: An item with the same key has already been added. Key: C:\git\core\Web\Web.Connect\obj\debug\net6.0\build-gz\bxkpRzBw.gz [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error :    at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error :    at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error :    at Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.GroupExistingStaticWebAssets(Dictionary`2 assemblyAssets, Dictionary`2 nativeAssets, Dictionary`2 satelliteAssemblyAssets, Dictionary`2 symbolAssets, Dictionary`2 compressedRepresentations) [C:\git\core\Web\Web.Connect\Web.Connect.csproj]
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk.BlazorWebAssembly\targets\Microsoft.NET.Sdk.BlazorWebAssembly.6_0.targets(404,5): error :    at Microsoft.NET.Sdk.BlazorWebAssembly.ComputeBlazorPublishAssets.Execute() [C:\git\core\Web\Web.Connect\Web.Connect.csproj]

好的 - 所以某些资产正试图在 ComputeBlazorPublishAssets 中多次发布?

发现信息表明将<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles> 添加到*.csproj 可能会有所帮助,但没有任何区别。

我已确保wasm-tools 已通过dotnet workload install wasm-tools 安装。

通过 VS 2022 运行“发布”也会出现同样的错误。

我不知道如何调试它,或者弄清楚生成了两次的内容,或者如何解决这个问题。

谢谢。

【问题讨论】:

    标签: c# blazor-webassembly .net-6.0


    【解决方案1】:

    好的,

    在对 binlog 文件进行大量调查后,我设法将其归结为我引用的库(这是与解决方案中的其他项目共享的 netstandard 2.0 项目)也输出了一个 @ 987654324@ 文件(可能是由于早期我们同时针对netstandard2.0net472)。

    查看 MSBuild bin 日志:

    因此,有两个同名的压缩文件 - 一个引用实际的 *.dll,但另一个引用 *.dll.config

    我删除了 app.config(它并不是真正需要的,可能由于某些历史原因而存在),现在它按预期发布。

    【讨论】:

      猜你喜欢
      • 2017-01-02
      • 2017-08-02
      • 2011-01-27
      • 1970-01-01
      • 2018-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多