将运行程序所需的多个文件分组为一个可执行文件

发布于 2024-11-09 08:25:01 字数 218 浏览 2 评论 0原文

有时我会创建供个人使用的小项目。因此,我只需从项目中提取调试目录,并在需要使用应用程序时运行可执行文件。我如何将所有这些文件:

在此处输入图像描述

合并到一个可执行文件中。我知道我可以将该文件夹放置在我的 C 驱动器中的某个位置,并有一个可执行文件的快捷方式。我只是想知道这是怎么做到的。

There are times where I create small projects for personal use. Therefore I just extract the debug directory from my project and run the executable file whenever I need to use my application. How could I combine all this files:

enter image description here

into one executable. I know I can place that folder somewhere in my c drive and have a shortcut to the executable file. I am just curious to know how could this be done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萝莉病 2024-11-16 08:25:01

这里有两件事需要注意:

  1. 您永远不应该分发应用程序的调试版本。始终在“发布”模式下编译应用程序的最终版本,您将让人们使用该应用程序(即使这些人只有您)。

    这样做的原因有很多很多,但最明显的一个是在“发布”模式下编译将启用编译时和运行时优化,使您的代码能够运行明显更快。

  2. 运行您的应用程序实际上只需要您所显示的文件之一,即 .EXE 文件本身。这是您唯一需要分发的一个。其余文件仅提供调试信息并由 Visual Studio 使用。由于应用程序编写完成后您可能不需要对其进行调试,因此您根本不需要这些文件。

    事实上,只有在您的应用程序使用 .DLL 库文件时,您才需要分发 .EXE 文件之外的任何内容。它们可能是您从同一解决方案中的另一个项目中自己创建的库,也可能是其他人编写的库,您正在使用它们为自己的代码提供一些功能。

Two things are important to realize here:

  1. You should never distribute the Debug version of an application. Always compile in "Release" mode for the final release of your application, the one you're going to let people use (even if those people are just you).

    There are many, many reasons to do this, but the most obvious one is that compiling in "Release" mode will enable both compile-time and run-time optimizations that allow your code to run significantly faster.

  2. Only one of the files you've shown there is actually required to run your application, and that's the .EXE file itself. That's the only one you have to distribute. The rest of the files just provide debugging information and are used by Visual Studio. Since you probably won't need to debug the application once it's written, you don't need these files at all.

    In fact, the only time you need to distribute anything beyond the .EXE file is if you have .DLL library files that your app uses. They might be libraries that you created yourself from another project within the same solution, or they might be libraries that someone else wrote and you're using to provide some functionality to your own code.

神仙妹妹 2024-11-16 08:25:01

您是否尝试过仅将 exe 文件复制到单独的目录并运行该 exe?您的应用程序运行不需要屏幕截图中列出的其他 3 个文件。

Have you try copying just the exe file to a separate directory and run the exe? The other 3 files listed in your screenshot are not needed for your application to run.

只想待在家 2024-11-16 08:25:01

您不需要合并整个文件夹,只需将一个文件“ConsoleApplication26.exe”移动到您关心的任何位置并单独运行它即可。其他文件仅包含在 Visual Studio IDE 中调试程序时使用的信息。

You don't need to combine the whole folder, you could just move the one file 'ConsoleApplication26.exe' to wherever you care to and run it happily on its own. The other files just contain information that are used when you debug the program in the Visual Studio IDE.

好多鱼好多余 2024-11-16 08:25:01

在这种特定情况下,您只需要 .exe 文件,因为其余文件包含调试信息等。

但一般来说,dll 文件可以放置在全局程序集缓存(或 GAC)中。 有关 GAC 的 MSDN 文章GAC 正如评论中提到的,这应该由安装程序处理,但这是避免将 dll 留在程序文件夹中的方法。正如科迪提到的,通常最好将它们留在程序文件夹中。

如果您有图像或文本文件等资源,可以通过在 Visual Studio 中将它们设置为嵌入资源来将它们嵌入到可执行文件中。

然后,它们可以作为执行程序集中的流进行访问(this.GetType().Assembly.GetManifestResourceStream(name),其中 name 是默认命名空间“.”文件名。如果需要,可以参考 GetManifestResourceNames 方法 但包含资源

也意味着您必须重写一些资源加载才能使用资源流,因此需要一些额外的工作。

In this specific case you only need the .exe file, since the rest contains debug information etc.

But generally speaking dll files can be places in the global assembly cache (or GAC). MSDN article on the GAC This should - as mentioned in the comments - be handled by an installer, but is the way to avoid leaving dll's in the program folder. As Cody mentions it will in general be better to leave them in the program folder.

If you have resources like images or text files these can be embedded inside the executable by setting them as embedded resources in Visual Studio.

They are then accessible as streams inside the executing assembly (this.GetType().Assembly.GetManifestResourceStream(name) where name is the default namespace "." filename. The method GetManifestResourceNames can be consulted if you want to learn the names of the embedded resources.

But including resources also means that you will have to rewrite some of the resource loading to use the resource streams, so it requires some extra work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文