【问题标题】:ILMerge ignores bindingRedirectILMerge 忽略 bindingRedirect
【发布时间】:2016-05-13 21:25:28
【问题描述】:

我有项目 A,它引用程序集 B 和程序集 C。程序集 B 也引用程序集 C,但在项目 A 之外的另一个版本中。项目 A 中通过 NuGet 引用了两个程序集(B 和 C)(尽管两者程序集在我自己的控制之下,所以如果我必须改变它们的构建方式) 我希望这张照片能说明我的意思: 程序集层次结构:

在项目 A 中,我有一个 app.config,它在程序集 C 上有一个 bindingRedirect,将所有版本从 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 版本。 但是,如果我尝试将项目 A 的输出(什么也是程序集)与程序集 B (1.0) 和程序集 C (1.1) 合并,我会收到以下错误:

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。 知道如何在不总是更新层次结构链中的所有项目的情况下解决这个问题吗?或者对我做错了什么有什么建议?

【问题讨论】:

  • 到目前为止,我发现的唯一其他解决方案是不要触及项目 C 的 AssemblyVersion-Attribute,而是使用 AssemblyInformationalVersion-Attribute。这样我就可以使用 NuGet 部署较新的版本,而无需更新层次链中的所有项目。

标签: .net app-config .net-assembly ilmerge assembly-binding-redirect


【解决方案1】:

ILRepack 支持这种情况,并将对程序集 C 的任何调用重定向到合并版本。

但是,它会在不查看绑定重定向的情况下执行此操作,并假定您要求合并的版本(在命令行上)是您要使用的唯一版本。如果版本 1.01.1 以不兼容的方式不同(例如,B 中使用的类型已从 C 1.1 中删除),则行为并未真正定义。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多