引用另一个dll的dll的costura.fody [英] costura.fody for a dll that references another dll

查看:789
本文介绍了引用另一个dll的dll的costura.fody的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个小程序,使用 LibGit2Sharp ,并尝试使用 Costura.Fody 嵌入所有内容,这样我只有一个exe可以分发(实际上,也有两个配置文件,但是没关系)。



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



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





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'引发了异常。 --->
System.DllNotFoundException:无法加载DLL git2-1196807:找不到
指定的模块。 (来自HRESULT的异常:
0x8007007E)...


我所做的一些事情给了我一个错误, LibGet2Sharp dll是无法访问的(不是关于 git2-1196807 的错误),但是我认为这只是在我



我将不胜感激。这让我感到困惑。如果将 git2-1196807.dll 文件放在已部署位置 .\lib\win32\x86和64位等效文件中,则它可以正常运行,但是



想法?

解决方案



对于每个dll,我都将Build Action设置为Embedded Resource:





最后,FodyWeavers.xml是:

 <?xml version = 1.0编码= utf-8吗? 
< Weavers>
< costura IncludeDebugSymbls =‘false’>
< Unmanaged32Assemblies>
git2-15e1193
< / Unmanaged32Assemblies>
< Unmanaged64Assemblies>
git2-15e1193
< / Unmanaged64Assemblies>
< / costura>
< / Weavers>

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


I have a small exe I've written that uses LibGit2Sharp and am trying to use Costura.Fody to embed everything so I only have a single exe to distribute (actually, there are two config files as well, but that's ok).

The problem seems to be that LibGet2Sharp.dll has a fairly firm reference to git2-1196807.dll, and I can't seem to figure out how to embed the latter in the way the former can use. I've tried several things, but I think my best attempt is:

all of these .dll's are copied from the solution's packages folder and set to Build Action = Embedded Resource and Copy to Output Directory = Do Not Copy.

The LibGit2Sharp reference is set to Copy Local = false, and I have tried the simple route in FodyWeavers.xml:

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

and a more complex is:

<?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>

However, I always get an error, not when opening the exe, but when I click the button that first uses the git library:

...'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)...

A few things I've done have given me an error that the LibGet2Sharp dll is inaccessible (and not the error about git2-1196807), but I think that's just when I've crippled Fody.

I would appreciate any advice you can give; this has me baffled. If I put the git2-1196807.dll file in the deployed location ".\lib\win32\x86" and the 64bit equivalent, then it runs fine, but that defeats the point in using costura.fody.

thoughts?

解决方案

Figured this out with some help from this question and had to add some work of my own.

Essentially, you need to create a pair of folders in the project, called Costura32 and Costura64 and put the appropriate version of the dll in there, and set them to 'Embedded resource'. Then the weaver can include them in the exe when building the solution.

In my case, I was using the LibGit2Sharp dll, which relies on git2-15e1193.dll, so I have this as part of my solution:

and for each of those dll's, I have the Build Action set to Embedded Resource:

Finally, the FodyWeavers.xml is:

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

Make sure to leave the .dll off the dll names in the FodyWeavers.xml file.

这篇关于引用另一个dll的dll的costura.fody的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆