ILMerge error: Key needs to be greater than 0

ILMerge error: Key needs to be greater than 0

我们在构建服务器上有一个步骤,将我们的 DLL 合并为一个以便于传输。

在我们的 QA 环境中,运行 ILMerge

时出现以下错误
An exception occurred during merging:
Key needs to be greater than 0.
Parameter name: key
   at System.Compiler.TrivialHashtable.get_Item(Int32 key)
   at System.Compiler.Ir2md.GetTypeSpecIndex(TypeNode type)
   at System.Compiler.Ir2md.GetMemberRefIndex(Member m)
   at System.Compiler.Ir2md.GetMethodToken(Method m)
   at System.Compiler.Ir2md.VisitConstruct(Construct cons)
   at System.Compiler.Ir2md.VisitAssignmentStatement(AssignmentStatement assignment)
   at System.Compiler.Ir2md.VisitBlock(Block block)
   at System.Compiler.Ir2md.VisitBlock(Block block)
   at System.Compiler.Ir2md.VisitMethodBody(Method method)
   at System.Compiler.Ir2md.VisitMethod(Method method)
   at System.Compiler.Ir2md.VisitClass(Class Class)
   at System.Compiler.Ir2md.VisitModule(Module module)
   at System.Compiler.Ir2md.SetupMetadataWriter(String debugSymbolsLocation)
   at System.Compiler.Ir2md.WritePE(Module module, String debugSymbolsLocation, BinaryWriter writer)
   at System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName)
   at System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
   at ILMerging.ILMerge.Merge()
   at ILMerging.ILMerge.Main(String[] args)

知道如何解决这个问题吗?我们有太多的代码和太多的 DLL,我无法提供更多关于我们试图合并的 DLL 的信息。

被合并的代码今天早上从我们的开发线中分支出来——代码与开发线相同,能够很好地进行 ILMerge。

合并错误发生在我们的本地机器和我们的构建服务器上。

我知道这不是很多,但这就是我所拥有的!

在发布模式下构建代码后,IL 合并工作正常。

不完全是答案,但您可以尝试 ILRepack,它与 ILMerge 具有相同的语法,但代码是开源的,异常(如果有)可能更明确(虽然不能保证)。

此外,如果您的目标程序集已签名,'key' 可能会以某种方式引用其签名密钥,以防它帮助您走上正轨。

我的回答有点过时了,但我遇到了同样的问题,也许它对某人有帮助。

我有过例外,在 Visual Studio 的 post 构建事件中有 ILMerge 操作。我知道这听起来有多愚蠢,但解决方案是用普通方法替换所有 delegatesActionFunc<>。在发布模式下构建时问题也消失了

https://github.com/isukces/ILMerge 试试我的 ILMerge 分支。它永远不会因否定键异常而崩溃。