c# - costura.fody 用于引用另一个 dll 的 dll

标签 c# .net dll libgit2sharp fody-costura

我有一个我编写的小 exe,它使用 LibGit2Sharp 并尝试使用 Costura.Fody 来嵌入所有内容,所以我只有一个 exe 可以分发(实际上,还有两个配置文件,但没关系。

问题似乎是 LibGet2Sharp.dllgit2-1196807.dll 有相当明确的引用,我似乎无法弄清楚如何嵌入后者在前者可以使用的方式。我已经尝试了几件事,但我认为我最好的尝试是:

所有这些 .dll 都从解决方案的 packages 文件夹中复制并设置为 Build Action = Embedded ResourceCopy to Output Directory = Do Not Copy.

add .dll's to project explicitely

LibGit2Sharp 引用设置为 Copy Local = false,我已经尝试了 FodyWeavers.xml 中的简单路径:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <Costura>
  </Costura>
</Weavers>

更复杂的是:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <Costura>
    <Unmanaged64Assemblies>
      Costura64\LibGit2Sharp
      Costura64\git2-1196807
    </Unmanaged64Assemblies>
    <Unmanaged32Assemblies>
      Costura32\LibGit2Sharp
      Costura32\git2-1196807
    </Unmanaged32Assemblies>
  </Costura>
</Weavers>

但是,我总是报错,不是在打开exe的时候,而是在点击最先使用git库的按钮的时候:

...'LibGit2Sharp.Core.NativeMethods' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'git2-1196807': The specified module could not be found. (Exception from HRESULT: 0x8007007E)...

我做的一些事情给了我一个错误,即 LibGet2Sharp dll 是不可访问的(而不是关于 git2-1196807 的错误),但我认为那是就在我使 Fody 瘫痪的时候。

如果您能提供任何建议,我将不胜感激;这让我感到困惑。如果我将 git2-1196807.dll 文件放在部署位置“.\lib\win32\x86”和 64 位等效文件中,那么它运行良好,但这与使用 costura.fody 的意义不符.

想法?

最佳答案

this question 的帮助下解决了这个问题并且不得不添加一些我自己的作品。

基本上,您需要在项目中创建一对文件夹,分别称为 Costura32 和 Costura64,并将相应版本的 dll 放在那里,并将它们设置为“嵌入式资源”。然后编织者可以在构建解决方案时将它们包含在 exe 中。

在我的例子中,我使用的是 LibGit2Sharp dll,它依赖于 git2-15e1193.dll,所以我将其作为我的解决方案的一部分:

enter image description here

对于每个 dll,我都将构建操作设置为嵌入式资源:

enter image description here

最后,FodyWeavers.xml 是:

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <costura IncludeDebugSymbls='false'>
    <Unmanaged32Assemblies>
      git2-15e1193
    </Unmanaged32Assemblies>
    <Unmanaged64Assemblies>
      git2-15e1193
    </Unmanaged64Assemblies>
  </costura>
</Weavers>

确保在 FodyWeavers.xml 文件中的 dll 名称中保留 .dll。

关于c# - costura.fody 用于引用另一个 dll 的 dll,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47079595/

相关文章:

c# - .net 请求浏览器版本不一致

c# - 如何在与 SQL Server Express 一起使用的 Windows 服务中定义对 SQL Server 的依赖关系

C++:在运行时添加一个dll目录

c# - 托管 C++ 将 float *OUT 作为参数传递

c# - 在充当容器的 WPF 控件中,如何放置内容?

c# - .Net 属性功能是在编译时还是在运行时或两者都使用?

c++ - 未定义基类?

python - SWIG C++ 预编译 DLL

c# - 尝试删除条目时接收 System.IO.IOException

c# - 仅在“编辑并继续”中出现错误 CS7038(无法发出模块)