使用<bindingredirect>时,使用mono mkbundle工具创建静态编译的二进制文件

时间:2016-02-03 18:32:14

标签: linker mono mkbundle

我正在尝试使用mkbundle生成静态编译的二进制文件,但在配置文件中使用<bindingRedirect>的依赖项时遇到问题。

如果提供了--deps选项,则mkbundle会尝试加载引用的程序集,但无法找到在运行时根据app.config中的bindingRedirect重定向的引用。

使用mkbundle时处理<bindingRedirect>依赖项的正确方法是什么?

命令:

  

user @ user-lubuntu:mkbundle --deps --static   Integrate.ServiceName.Gateway.exe * .dll -o newbin

结果:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies
File name: 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
  at System.AppDomain.Load (System.String assemblyString, System.Security.Policy.Evidence assemblySecurity, Boolean refonly) <0x7f1dd3d2e470 + 0x000a2> in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain:Load (string,System.Security.Policy.Evidence,bool)
  at System.Reflection.Assembly.ReflectionOnlyLoad (System.String assemblyString) <0x7f1dd3da1960 + 0x00022> in <filename unknown>:0 
  at IKVM.Reflection.Universe.DefaultResolver (System.String refname, Boolean throwOnError) <0x404a4590 + 0x0007e> in <filename unknown>:0 
  at IKVM.Reflection.Universe.Load (System.String refname, IKVM.Reflection.Module requestingModule, Boolean throwOnError) <0x404a3b20 + 0x00087> in <filename unknown>:0 
  at IKVM.Reflection.Universe.Load (System.String refname) <0x404a3af0 + 0x0001b> in <filename unknown>:0 
  at MakeBundle.QueueAssembly (System.Collections.Generic.List`1 files, System.String codebase) <0x404b1590 + 0x001eb> in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies
File name: 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'
  at System.AppDomain.Load (System.String assemblyString, System.Security.Policy.Evidence assemblySecurity, Boolean refonly) <0x7f1dd3d2e470 + 0x000a2> in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.AppDomain:Load (string,System.Security.Policy.Evidence,bool)
  at System.Reflection.Assembly.ReflectionOnlyLoad (System.String assemblyString) <0x7f1dd3da1960 + 0x00022> in <filename unknown>:0 
  at IKVM.Reflection.Universe.DefaultResolver (System.String refname, Boolean throwOnError) <0x404a4590 + 0x0007e> in <filename unknown>:0 
  at IKVM.Reflection.Universe.Load (System.String refname, IKVM.Reflection.Module requestingModule, Boolean throwOnError) <0x404a3b20 + 0x00087> in <filename unknown>:0 
  at IKVM.Reflection.Universe.Load (System.String refname) <0x404a3af0 + 0x0001b> in <filename unknown>:0 
  at MakeBundle.QueueAssembly (System.Collections.Generic.List`1 files, System.String codebase) <0x404b1590 + 0x001eb> in <filename unknown>:0

我们通读了这个类似的stackoverflow问题: Mkbundle Mono Assembly binding redirection

但是,手动包含文件的解决方案似乎不适合我们:

命令:

  

user @ user-lubuntu:mkbundle --nodeps --static   Integrate.ServiceName.Gateway.exe ALL_PACKAGES_WITH_FULL_PATH_SEPARATED_BY_SPACES -o newbin

结果:

OS is: Linux
Note that statically linking the LGPL Mono runtime has more licensing restrictions than dynamically linking.
See http://www.mono-project.com/Licensing for details on licensing.
Sources: 21 Auto-dependencies: False
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.ServiceName.Gateway.exe
config from: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.ServiceName.Gateway.exe.config
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.Cache.Redis.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.MassTransit.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.Nancy.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.ServiceName2.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.ServiceName.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Integrate.ServiceName.Service.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Magnum.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/MassTransit.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/MassTransit.Transports.RabbitMq.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/MongoDB.Bson.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/MongoDB.Driver.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Nancy.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Nancy.Hosting.Self.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/Newtonsoft.Json.dll
   embedding: /usr/lib/mono/gac/RabbitMQ.Client/4.0.0.0__b03f5f7f11d50a3a/RabbitMQ.Client.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/ServiceStack.Common.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/ServiceStack.Interfaces.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/ServiceStack.Redis.dll
   embedding: /media/sf_Share/dev/builder/Integrate.ServiceName.Gateway/bin/Debug/ServiceStack.Text.dll
Compiling:
as -o temp.o temp.s 
cc -o newbin -Wall `pkg-config --cflags mono-2` temp.c  `pkg-config --libs-only-L mono-2` -Wl,-Bstatic -lmono-2.0 -Wl,-Bdynamic `pkg-config --libs-only-l mono-2 | sed -e "s/\-lmono-2.0 //"` temp.o
temp.c: In function ‘install_dll_config_files’:
temp.c:77:2: warning: pointer targets in passing argument 2 of ‘mono_register_config_for_assembly’ differ in signedness [-Wpointer-sign]
  mono_register_config_for_assembly ("Integrate.ServiceName.Gateway.exe", assembly_config_Integrate_ServiceName_Gateway_exe);
  ^
In file included from temp.c:2:0:
/usr/lib/pkgconfig/../../include/mono-2.0/mono/metadata/assembly.h:102:24: note: expected ‘const char *’ but argument is of type ‘const unsigned char *’
MONO_API void          mono_register_config_for_assembly (const char* assembly_name, const char* config_xml);
                        ^
Done
  

user @ user-lubuntu:./ newbin

An exception was thrown during service bus creation
  at MassTransit.ServiceBusFactory.New (System.Action`1 configure) <0x4015c450 + 0x000fb> in <filename unknown>:0 
  at Integrate.MassTransit.ServiceBootstrapper.Initialize (System.String queueEndpoint) <0x4015c100 + 0x0007b> in <filename unknown>:0 
  at Integrate.ServiceName.Bootstrapper.ConfigureServiceBus (Nancy.TinyIoc.TinyIoCContainer iocContainer) <0x4015ba50 + 0x0009b> in <filename unknown>:0 
  at Integrate.ServiceName.Bootstrapper.ApplicationStartup (Nancy.TinyIoc.TinyIoCContainer iocContainer, IPipelines pipelines) <0x4015b9f0 + 0x0001f> in <filename unknown>:0 
  at Nancy.Bootstrapper.NancyBootstrapperBase`1[TContainer].Initialise () <0x4011ee30 + 0x00416> in <filename unknown>:0 
  at Nancy.Hosting.Self.NancyHost..ctor (INancyBootstrapper bootstrapper, Nancy.Hosting.Self.HostConfiguration configuration, System.Uri[] baseUris) <0x4011ed70 + 0x0007e> in <filename unknown>:0 
  at Integrate.ServiceName.Program.Main (System.String[] args) <0x40012dc0 + 0x00207> in <filename unknown>:0

0 个答案:

没有答案