Visual Studio C# MSBuild.ILMerge.Task 程序集未标记为仅包含托管代码的问题

Visual Studio C# MSBuild.ILMerge.Task problem with The assembly is not marked as containing only managed code

我有 2 个项目的解决方案,例如:

我想在 MainDLL 中合并 LibraryDLL。我的应用程序只需要导入一个文件作为插件。 我下载了 NUGet Packacged:

设置后,当我按构建时收到以下错误:

ILMerge.Merge: The assembly 'ChilkatDotNet4' is not marked as containing only managed code.
(Consider using the /zeroPeKind option -- but read the documentation first!)

我没有直接使用它,也不需要它,但它可能被两个项目中其他引用的 dll 引用(我不需要包含它,因为应用程序已经有了它)。 如何避免这个问题? 我尝试设置标志:

<!-- See ILMerge documentation -->
<ILMergeAllowZeroPeKind></ILMergeAllowZeroPeKind>

对或错但没有变化

Visual Studio C# MSBuild.ILMerge.Task problem with The assembly is not marked as containing only managed code

我认为您的 LibraryDLL 是一个 c++ 本机动态库项目,ILMerge 无法处理包含本机代码的程序集。

您必须在使用前 运行 时间提取 dll,或者发送 dll。

建议

1) 我想你已经为 运行 这个命令写了一个预构建事件或 post-build 事件,所以在你的命令中,请添加 /zeroPeKind.

喜欢ilmerge /target:xxxx /zeroPeKind /out:xxxxx xxxxxxxxx

2)此外,您也可以尝试this workaround(use DllImport)解决您的问题。

使用 /zeroPeKind 对我来说是不成功的(并不意味着它是错误的方式)。 我也无法重建这个原生 C++ 库,因为它来自外部供应商。

检查后 https://github.com/emerbrito/ILMerge-MSBuild-Task/wiki

Merge Assemblies With Copy Local = True

我已经更改了所有其他参考 属性 设置 复制 Local 为 false。

我离开 Copy Local = true 只是为了引用我想与我的主项目合并的共享项目库。