Blazor 和 protobuf-net 不会在发布中编译



如果将 protobuf-net nuget 包添加到 Blazor WASM 应用并在调试中编译,一切正常。

如果你切换到发布VS说:

未处理的异常。Mono.Linker.LoadException:处理时出错 'protobuf-net, 版本=2.4.0.0, 文化=中性, 公钥令牌=257b51d87d2e4d67'

我该如何解决这个问题?

通常,这种类型的错误意味着您需要将链接器配置为不剥离反射繁重的程序集;我这始于:

<ItemGroup>
<BlazorLinkerDescriptor Include="LinkerConfig.xml" />
</ItemGroup>

在 csproj 中,以及包含(至少(以下内容的LinkerConfig.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<linker>
<assembly fullname="protobuf-net" />
</linker>

请注意,我也在研究protobuf-net的AOT/pre-gen选项(使用protobuf-net。v3 中的核心,没有任何反射代码(,这将是这里的理想方案;但这至少需要几个月的时间。

最新更新