我正在开发一个使用 iTextSharp.dll 和 WebCam_Capture.dll 的 C# 程序。当我构建程序时,它会在调试文件夹中创建可执行文件,并且还会按预期将这两个 dll 复制到调试文件夹中。我想将它们合并成一个可执行文件,但是我失败了。这两个库通常在解决方案资源管理器的参考中可见。我还将它们添加为资源。可执行文件的大小变得更大,等于三个文件的总和,但是可执行文件仍然需要其目录中的这些库...我使用了资源文件的“构建操作”属性,但没有变化。我也尝试过 ILmerge 但它给了我一个错误。那我该怎么办呢?
更新:这是我从 ILmerge 得到的:
An exception occurred during merging:
Unresolved assembly reference not allowed: System.Core.
at System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly)
at System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type)
顺便说一句,它只是一个 Windows 应用程序,是一个需要填写并打印为 pdf 格式的表格,其中包含通过网络摄像头拍摄的照片(如果有)。谢谢大家!
I'm working on a C# program that uses iTextSharp.dll and WebCam_Capture.dll. When I build the program, it creates executable in the debug folder and it also copies these two dll's to the debug folder as expected. I want to merge them into a single executable, however I failed. These two libraries are visible in the references normally in the solution explorer. I also add them as resources. Executable size got bigger which equals the sum of three files, nevertheless the executable still requires these libraries in its directory... I played with "build action" property of the resource files but no change. I also tried ILmerge but it gave me an error. so what should I do?
Update: This is what I get from ILmerge:
An exception occurred during merging:
Unresolved assembly reference not allowed: System.Core.
at System.Compiler.Ir2md.GetAssemblyRefIndex(AssemblyNode assembly)
at System.Compiler.Ir2md.GetTypeRefIndex(TypeNode type)
It is just a windows application by the way, a form to be filled and printed as pdf with a photo taken via webcam if available. Thanks all!
发布评论
评论(8)
这是代码:
希望有帮助,
巴勃罗
Here is the code:
Hope it helps,
Pablo
您可以使用 ILMerge 将多个程序集合并在一起。您已经说过您这样做了,并且收到了错误。虽然我不知道为什么,但您可以使用另一种选择:如果这些库是开源的(并且它们的许可证与您的兼容),您可以下载源代码,将其添加到您的项目中并进行编译。这将导致单个组件。
ILMerge 页面还列出了 Jeffrey Richter 的博客作为解决您问题的另一种选择:
You can use ILMerge to merge multiple assemblies together. You've already said you did this, and you've received an error. Though I don't know why, you can use an alternative: if the libraries are open source (and their licenses are compatible with yours), you can download the source code, add it to your project and compile. This will result in a single assembly.
The ILMerge page also lists Jeffrey Richter's blog as yet another alternative to solve your issue:
我稍微修改了巴勃罗的代码,它对我有用。
它没有正确获取 DLL 的资源名称。
I modified Pablo's code a little bit and it worked for me.
It was not getting the DLL's resource name correctly.
您正在寻找的答案:
The answer you are looking for:
查看应用域上的 AssemblyResolve 事件。
我没有示例,但您基本上可以检查所要求的内容并流回资源 DLL。我相信 LinqPAD 做得很好 - 你可以看看 Joseph Albahari 使用反编译器等的实现。
Check out the AssemblyResolve event on the app domain.
I don't have a sample but you basically check what is asked for and stream back the resource DLL. I believe LinqPAD does this well - you could have a look at Joseph Albahari's implementation with a decompiler etc.
将此匿名函数代码添加到我们的应用程序构造函数的顶部。这将从同一项目中的嵌入资源添加 dll。
Add this anonymous function code on the top of our application constructor. This will add dll from embedded resource in same project.
我知道这个主题很旧,但我会为未来想要使用它的人编写它。
我基于userSteve的代码。
我建议改变这一点。
这样,
即使命名空间与程序集名称不同,它
也可以工作,如果您想使用目录中的 DLL,则可以像这样使用它(以目录 Resources 为例),
如果您仍然找不到将此代码放在 C# 表单中的位置应用程序将其粘贴到文件“Program.cs”上方行:
和下方行:
I know that topic is old but i'll write it for future persons that will want to use it.
i base on code by userSteve.
i would suggest to change this.
into this
that way it would work even if namespace is different than assembly name
also if you want to use DLL from directory you can use it like that (directory Resources as Example)
if you still can't find where place this code in C# Form application paste it inside file "Program.cs" above line:
and below lines:
您没有引用使用 WPF,但如果引用了,这可能是导致错误的原因。如果没有,ILMerge 应该可以正常工作。如果您使用的是 WPF,这里有一个效果很好的解决方案:
http://blogs.interknowlogy.com/2011/07/13/merging-a-wpf-application-into-a-single-exe/
You didn't reference using WPF, but if you are, this could be the cause of your error. If not, ILMerge should work fine for you. If you are using WPF, here is a solution that works well:
http://blogs.interknowlogy.com/2011/07/13/merging-a-wpf-application-into-a-single-exe/