【问题标题】:Mkbundle Mono Assembly binding redirectionMkbundle Mono 程序集绑定重定向
【发布时间】:2015-06-10 18:05:03
【问题描述】:

我有一个在 Windows 上运行良好的示例 .NET 应用程序,我的 Ubuntu 环境使用单声道。

我正在尝试使用 Mkbundle 创建单个本机程序集,以便我可以使用 busybox 将其 docker 容器化并保持较小的大小而不是通常巨大的臃肿容器。

我遇到的问题是 Json.net,我认为这是由于来自 app.config 文件的程序集绑定重定向,还有其他人遇到过这个问题吗?

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" /></startup>

  <runtime>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

      <dependentAssembly>

        <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />

        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />

      </dependentAssembly>

    </assemblyBinding>

  </runtime>

</configuration>

无论是否使用 --static 都会产生以下错误

【问题讨论】:

    标签: c# mono docker mkbundle


    【解决方案1】:

    我解决它的方法是指定 --nodeps 标志。

    mkbundle --nodeps -o console OutsideSourcesAPI.exe *.dll
    

    但是,当你运行它时,它可能会给你类似...的错误

    The assembly mscorlib.dll was not found or could not be loaded.
    

    Unhandled Exception: System.IO.FileNotFoundException: 
    Could not load file or assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies.
    

    然后您必须手动指定任何缺少的依赖项(我知道,有点臭)

    mkbundle --nodeps -o console OutsideSourcesAPI.exe *.dll mscorlib.dll System.Xml.dll
    

    【讨论】:

      【解决方案2】:

      答案有点晚,但有同样的问题,仅仅这样做还不够,因为我想静态链接 Mono 运行时(使用 --static 选项)。这是由于缺少 --skip-scan 和/或 --nodeps 缺少的 GAC 程序集,包括它们可能具有的任何传递依赖项。当然这只会影响没有安装 Mono 的机器(如果机器上有 Mono 的 GAC,它仍然会使用 Mono 的 GAC),这也使得测试变得更加困难。

      提供 -skip-scan 和 -nodeps 意味着您需要自己提供 DLL 列表(绕过 mkbundle 程序集扫描程序),允许您手动执行此操作,或者 write your own scanner which I did 获取每个程序集,包括 .NET 中的程序集框架。我不想手动列出每一个程序集,如果我错过了一个程序集,就会出现运行时错误。有了这个,我也能够解决 app.config 程序集绑定问题。

      【讨论】:

        【解决方案3】:

        添加 --skip-scan 标志似乎可以解决问题,而无需求助于 --nodeps 和依赖 dll 的手动列表。

        mkbundle -z --deps --skip-scan MyApp.exe
        

        请注意,从单声道 4.2.3 开始,mkbundle 似乎更喜欢单声道分发中的程序集,而不是本地文件夹中的程序集。如果本地程序集和框架程序集之间存在命名冲突(可能是 System.Web.Http.dll 候选),这可能会导致问题。

        您可以通过在命令行上使用 ./ 前缀指定冲突的本地程序集来解决此问题

        mkbundle -z --deps --skip-scan MyApp.exe ./System.Web.Http.dll
        

        第二个问题似乎在新版本的单声道中得到了解决。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-04-27
          • 2017-02-16
          • 2019-12-21
          • 1970-01-01
          • 2021-10-01
          • 2021-10-18
          • 2021-01-15
          • 2011-03-30
          相关资源
          最近更新 更多