在已编译的可执行文件中嵌入 DLL [英] Embedding DLLs in a compiled executable

查看:87
本文介绍了在已编译的可执行文件中嵌入 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将预先存在的 DLL 嵌入到已编译的 C# 可执行文件中(这样您只需分发一个文件)?如果可能,你会怎么做?

Is it possible to embed a pre-existing DLL into a compiled C# executable (so that you only have one file to distribute)? If it is possible, how would one go about doing it?

通常,我很乐意将 DLL 留在外面并让安装程序处理所有事情,但是有几个工作人员问过我这个问题,老实说我不知道​​.

Normally, I'm cool with just leaving the DLLs outside and having the setup program handle everything, but there have been a couple of people at work who have asked me this and I honestly don't know.

推荐答案

我强烈推荐使用 Costura.Fody - 迄今为止在程序集中嵌入资源的最佳和最简单的方法.它以 NuGet 包的形式提供.

I highly recommend to use Costura.Fody - by far the best and easiest way to embed resources in your assembly. It's available as NuGet package.

Install-Package Costura.Fody

将它添加到项目后,它会自动将复制到输出目录的所有引用嵌入到您的main 程序集中.您可能希望通过向项目添加目标来清理嵌入的文件:

After adding it to the project, it will automatically embed all references that are copied to the output directory into your main assembly. You might want to clean the embedded files by adding a target to your project:

Install-CleanReferencesTarget

您还可以指定是包含 pdb、排除某些程序集还是动态提取程序集.据我所知,还支持非托管程序集.

You'll also be able to specify whether to include the pdb's, exclude certain assemblies, or extracting the assemblies on the fly. As far as I know, also unmanaged assemblies are supported.

更新

目前,有些人正在尝试添加对 DNX 的支持.

Currently, some people are trying to add support for DNX.

更新 2

对于最新的 Fody 版本,您需要拥有 MSBuild 16(所以是 Visual Studio 2019).Fody 4.2.1 版将执行 MSBuild 15.(参考:Fody 仅在 MSBuild 16 及更高版本上受支持.当前版本:15)

For the lastest Fody version, you will need to have MSBuild 16 (so Visual Studio 2019). Fody version 4.2.1 will do MSBuild 15. (reference: Fody is only supported on MSBuild 16 and above. Current version: 15)

这篇关于在已编译的可执行文件中嵌入 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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