visual-studio 我可以在 exe(在 Visual Studio 中)中包含 dll 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/476993/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 10:06:00  来源:igfitidea点击:

Can I include dll in exe (in Visual Studio)?

visual-studiodllincludereleaseexec

提问by IAdapter

Possible Duplicate:
.NET windows application, can it be compressed into a single .exe?

可能的重复:
.NET windows 应用程序,能否将其压缩为单个 .exe?

To run my App I need AxInterop.WMPLib.dlland Interop.WMPLib.dllthat are located in Debug and Release folder. Is there any way to include those dlls into exe so my app is available in one file only?

要运行我需要的应用程序AxInterop.WMPLib.dllInterop.WMPLib.dll它位于 Debug 和 Release 文件夹中。有什么方法可以将这些 dll 包含到 exe 中,以便我的应用程序仅在一个文件中可用?

回答by Juliet

As long as your DLLs are .NET assemblies, then ILMergeshould be able to combine your exe and all of its dependencies into a single file.

只要您的 DLL 是 .NET 程序集,ILMerge 就应该能够将您的 exe 及其所有依赖项组合到一个文件中。

回答by IAdapter

You can use a tool like boxedapp or thinstall...

您可以使用 boxedapp 或 thinstall 之类的工具...

回答by John Smith

I also recommend boxedapp. It's great app!

我也推荐boxedapp。这是很棒的应用程序!

回答by cookre

Yes, I left out the code to write the file out...

是的,我省略了写文件的代码......

FileStream so=new FileStream("c:\\wherever\\x.dll",FileMode.Create);

so.Write(buf,0,ssize);

so.Close();

No extra utilities required.

不需要额外的实用程序。

回答by cookre

Include them as embedded. You can then extract them at run-time.

包括它们作为嵌入。然后您可以在运行时提取它们。

回答by cookre

For example, add x.dll to the project and set its Build Action to Embedded Resource.

例如,将 x.dll 添加到项目并将其 Build Action 设置为 Embedded Resource。

To extract:

提取:

 string AppPath=Assembly.GetExecutingAssembly().Location;
 Assembly ThisAssembly=Assembly.LoadFrom(AppPath);
 System.IO.Stream fs=ThisAssembly.GetManifestResourceStream("yourproectname.x.dll");
 int ssize=(int)fs.Length;
 byte [] buf=new byte[ssize];
 fs.Read(buf,0,ssize);
 fs.Close();