好吧,我的问题几乎与 Embedding DLLs in a compiled executable 相似,但是提供的非常好的答案 here 失去了与单声道运行时的兼容性,尽管它适用于 Windows。

那么如何使用 Fody ( Costura ) 并保持单声道兼容性。他们在 https://github.com/Fody/Costura#contents 的文档如下:



但即使在手动初始化 ConturaUtility 之后,它也不支持单声道运行时。

我不认为错误日志是相关的,但这里是:

Unhandled Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'CommandLine, Version=2.2.1.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32' or one of its dependencies.
File name: 'CommandLine, Version=2.2.1.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'CommandLine, Version=2.2.1.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32' or one of its dependencies.
File name: 'CommandLine, Version=2.2.1.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32'

最佳答案

在程序的 Main() 开头使用此代码:

AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => {
   String resourceName = "AssemblyLoadingAndReflection." +
      new AssemblyName(args.Name).Name + ".dll";
   using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
      Byte[] assemblyData = new Byte[stream.Length];
      stream.Read(assemblyData, 0, assemblyData.Length);
      return Assembly.Load(assemblyData);
   }
};

引用:https://blogs.msdn.microsoft.com/microsoft_press/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition/

关于c# - 使用 Fody 将 dll 嵌入到具有 Mono 支持的 exe 中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50583640/

10-10 07:22