You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 6环境发布Blazor WASM提示dotnet.exe退出代码1错误

问题现象
  • 本地localhost调试时Blazor WASM应用运行正常,执行发布操作时报错,错误信息为 "dotnet.exe" exited with code 1
  • 项目使用的目标框架版本为.NET 6
  • 报错项目Server.csproj原始配置如下:
<Project Sdk="Microsoft.NET.Sdk.Web">

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

 

  <ItemGroup>
    <PackageReference Include="AutoMapper" Version="11.0.1" />
    <PackageReference Include="Dapper" Version="2.0.123" />
    <PackageReference Include="DinkToPdf" Version="1.0.8" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
    <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.17.0" />
    <PackageReference Include="Microsoft.Win32.Primitives" Version="4.3.0" />
    <PackageReference Include="runtime.win.System.Console" Version="4.3.0" />
    <PackageReference Include="runtime.win.System.IO.FileSystem" Version="4.3.0" />
    <PackageReference Include="runtime.win.System.Net.Primitives" Version="4.3.0" />
    <PackageReference Include="runtime.win.System.Net.Sockets" Version="4.3.0" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.17.0" />
    <PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
    <PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
    <PackageReference Include="System.Net.Primitives" Version="4.3.0" />
    <PackageReference Include="System.Text.Encoding.Extensions" Version="4.3.0" />
    <PackageReference Include="Microsoft.NETCore.Targets" Version="6.0.0-preview.4.21253.7" PrivateAssets="all" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Client\PB.Client.csproj" />
    <ProjectReference Include="..\Shared\PB.Shared.csproj" />
  </ItemGroup>
 <ItemGroup>
    <None Update="libwkhtmltox.dll">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>


</Project>
问题根因

发布失败核心是项目存在大量版本不兼容的冗余依赖,依赖校验阶段直接触发dotnet进程退出:

  • 所有4.3.0版本的System.*、runtime.win.System.*、Microsoft.Win32.Primitives包是.NET Core 1.x时代的兼容包,.NET 6已将这些基础类库内建到框架中,手动引用低版本包会造成程序集版本冲突,发布时的依赖裁剪/校验步骤会直接报错
  • 引用的Microsoft.NETCore.Targets为6.0.0预览版,和正式版.NET 6 SDK存在兼容性问题,会导致依赖解析流程失败
  • Microsoft.AspNetCore.SignalR 1.1.0是适配.NET Core 2.x/3.x的独立旧包,.NET 6已将SignalR作为框架内建组件提供,单独引用低版本包会产生程序集冲突
  • Microsoft.AspNetCore.Components.WebAssembly.Server版本为6.0.2,和项目中其他6.0.3版本的ASP.NET Core组件版本不一致,小版本差也可能触发发布时的依赖冲突
  • 次要风险点:项目依赖的libwkhtmltox.dll是DinkToPdf加载的非托管原生库,若发布时指定的目标运行时(如linux-x64)和本地调试的win-x64不匹配,也会触发原生库加载错误,但当前报错核心为上述依赖冲突。
修复步骤

1. 清理冲突冗余依赖

直接编辑Server.csproj,移除所有冲突包,统一组件版本:

  • 删除所有4.3.0版本的System.*、runtime.win.System.*、Microsoft.Win32.Primitives包引用
  • 删除预览版Microsoft.NETCore.Targets包引用,.NET 6及以上版本无需手动引用该包
  • 删除1.1.0版本的Microsoft.AspNetCore.SignalR包引用,直接使用框架内建的SignalR功能即可
  • 将Microsoft.AspNetCore.Components.WebAssembly.Server版本升级到6.0.3,和其他ASP.NET Core组件版本对齐

清理完成后,包引用部分应保持如下结构:

<ItemGroup>
  <PackageReference Include="AutoMapper" Version="11.0.1" />
  <PackageReference Include="Dapper" Version="2.0.123" />
  <PackageReference Include="DinkToPdf" Version="1.0.8" />
  <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.3" />
  <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.3" />
  <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="6.17.0" />
  <PackageReference Include="Swashbuckle.AspNetCore" Version="6.3.0" />
  <PackageReference Include="System.Data.SqlClient" Version="4.8.3" />
  <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.17.0" />
</ItemGroup>

其余项目引用、原生dll复制规则的配置可以保留。

2. 清理缓存重新还原依赖

  • 关闭所有打开的IDE窗口,删除解决方案下所有项目的bin、obj文件夹
  • 打开VS开发者命令提示符,进入解决方案根目录,执行dotnet nuget locals all --clear清理本地Nuget缓存
  • 执行dotnet restore重新拉取所有正确版本的依赖

3. 验证发布

  • 若发布时指定了自定义目标运行时(如win-x64、linux-x64),确认对应平台版本的libwkhtmltox.dll已配置正确的复制规则,不要跨平台混用原生库
  • 执行dotnet publish -c Release验证发布流程,若仍存在报错,追加-v detailed参数执行命令,查看详细错误日志定位剩余冲突项即可。

内容的提问来源于stack exchange,提问作者dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.26 16:36:27