我有一个项目A,它引用了程序集B和程序集C。程序集B也引用了程序集C,但不是在项目A中。这两个程序集(B和C)都是通过NuGet在项目A中引用的(尽管这两个程序集都在我自己的控制之下,因此如果有必要,我可以更改它们的构建方式)。我希望这张图片可以说明我的意思:程序集层次结构:

在项目A中,我有一个在程序集C上有一个bindingRedirect的app.config,它将从0.0.0.0到1.1.0.0的所有版本指向1.1.0.0版本:
<dependentAssembly>
<assemblyIdentity name="C" publicKeyToken="447cd79fe2efd739" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
</dependentAssembly>所有程序集(B和C)都经过签名,并且确实具有强名称。如果我构建这个项目,所有的工作都很好,因为Visual Studio会考虑bindingRedirect,并且总是指向程序集C的1.1.0.0版本。但是,如果我试图用程序集B (1.0)和程序集C (1.1) ILMerge项目A(也是程序集)的输出,我会得到以下错误:
There was an error merging the assemblies:
An exception occurred during merging:
Unresolved assembly reference not allowed: C.
bei System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly)
bei System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type)
bei System.Compiler.Ir2md.VisitReferencedType(TypeNode type)
bei System.Compiler.Ir2md.VisitMethod(Method method)
bei System.Compiler.Ir2md.VisitClass(Class Class)
bei System.Compiler.Ir2md.VisitModule(Module module)
bei System.Compiler.Ir2md.SetupMetadataWriter(String debugSymbolsLocation)
bei System.Compiler.Ir2md.WritePE(Module module, String debugSymbolsLocation, BinaryWriter writer)
bei System.Compiler.Writer.WritePE(String location, Boolean writeDebugSymbols, Module module, Boolean delaySign, String keyFileName, String keyName)
bei System.Compiler.Writer.WritePE(CompilerParameters compilerParameters, Module module)
bei ILMerging.ILMerge.Merge()
bei ILMerging.ILMerge.Main(String[] args)如果我将程序集B的项目更新为也指向程序集C的1.1版本,则一切正常,但这不是我想要实现的目标。
所以我认为问题是,ILMerge没有考虑项目A的app.config。你知道如何在不总是更新层次链中所有项目的情况下解决这个问题吗?或者对我做错了什么有什么建议?
发布于 2016-02-09 23:16:16
ILRepack支持此方案,并将对程序集C的任何调用重定向到合并版本。
但是,它不会查看绑定重定向,并假定您请求合并的版本(在命令行上)是您唯一想要使用的版本。但是,如果1.0和1.1版本不兼容(例如,B中使用的类型已从C1.1中删除),则行为并未真正定义。
https://stackoverflow.com/questions/35198102
复制相似问题