如何捆绑机DLL与托管应用程序? [英] How to bundle native DLLs with a managed application?

查看:193
本文介绍了如何捆绑机DLL与托管应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个.NET项目,我有一对夫妇从本机DLL导入函数。

On a .NET project, I have a couple of functions imported from native DLLs.

目前添加本机DLL的项目,他们将被复制到在C#项目的根,他们的财产构建行动设置为复制到输出目录

Currently to add the native DLLs to the project, they are copied to the root of the C# project and their property Build action is set to Copy to output directory.

是否有捆绑机DLL一个更好的工作流程?

Is there a better workflow for bundling native DLLs?

推荐答案

一种选择,这是特别有用的,如果你想要一个exe文件的部署,是对DLL(S)嵌入到你的表现为资源。这是一种类似的方法是什么通常用于创建通用二进制代码,它可以从一个单一的文件x86或x64平台上运行。在这种情况下,你嵌入32位版本内的64位版本,并在需要的时候在运行时将其解压缩。你可以看到,与的Sysinternals 的二进制文件的操作。

One option, which is particularly useful if you want single exe deployment, is to embed the DLL(s) into your manifest as Resources. This is a similar approach to what is often used to create "universal binaries" which can run on either X86 or X64 platforms from a single file. In that case you embed the 64-bit version inside the 32-bit version and extract it at runtime when needed. You can see that in action with the Sysinternals binaries.

在你的情况,你会中嵌入一个本地二进制托管可执行文件,然后决定将其加载为IO流在运行时或提取,并从提取的路径引用它。在这两种情况下,你永远不用担心失去的资源,因为它是你的项目的一部分。

In your case, you would embed a native binary within the managed executable, then either load it as an IO stream at runtime or extract it and reference it from the extracted path. In either case, you never have to worry about "losing" the resource because it's part of your project.

如果你决定走这条路,得到的答案如何做到这一点已经在提供了若干倍。这里有一个这样的问题:
嵌入非托管的DLL成托管C#DLL

If you decide to go that route, the answer to how to do it has been provided several times over. Here's one such question: Embedding unmanaged dll into a managed C# dll

这篇关于如何捆绑机DLL与托管应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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