在 Visual Studio 中编译为独立可执行文件 (.exe)

发布于 2024-08-17 16:26:49 字数 158 浏览 5 评论 0原文

如何在 Visual Studio 中制作独立的 exe。它只是一个简单的控制台应用程序,我认为用户不会喜欢安装一个微小的控制台应用程序。我使用 Visual Studio 命令提示符编译了一个简单的 cpp 文件。即使未安装.NET Framework,exe 也能运行吗?我使用本机 C++ 代码。

how can I make a stand-alone exe in Visual Studio. Its just a simple Console application that I think users would not like to install a tiny Console application. I compiled a simple cpp file using the visual studio command prompt. Will the exe work even if the .NET framework is not installed? I used native C++ code.

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

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

发布评论

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

评论(8

转瞬即逝 2024-08-24 16:26:49

在您的项目文件夹中,有一个 bin 文件夹。 bin 文件夹内有 2 个文件夹,一个 Release 和一个 Debug。对于您完善的 .exe,您需要进入您的 Release 文件夹。

我不太确定这是否是你要问的

Inside your project folder their is a bin folder. Inside your bin folder, there are 2 folders, a Release and a Debug. For your polished .exe, you want to go into your Release folder.

I'm not quite sure if thats what youre asking

夜吻♂芭芘 2024-08-24 16:26:49

使用托管环境的任何内容(包括用 C# 和 VB.NET 编写的任何内容)都需要 .NET 框架。在这种情况下,您可以简单地重新分发 .EXE,但如果他们还没有安装适当的框架,则需要安装该框架。

Anything using the managed environment (which includes anything written in C# and VB.NET) requires the .NET framework. You can simply redistribute your .EXE in that scenario, but they'll need to install the appropriate framework if they don't already have it.

枕梦 2024-08-24 16:26:49

如果我理解正确的话,是的,你可以,但不能在 Visual Studio 下(据我所知)。
要强制编译器生成真正的、独立的可执行文件(这意味着您像使用任何其他语言一样使用 C#),您可以使用程序 mkbundle(随 Mono 一起提供)。这会将您的 C# 应用程序编译为真正的、无依赖项的可执行文件。

互联网上对此存在很多误解。它并没有像某些人所说的那样违背 .net 框架的目的,因为如果你一开始就没有使用过这些功能,你怎么会失去 .net 框架的未来功能呢?当您向应用程序发布更新时,在构建安装程序之前通过 mkbundle 处理器运行它并不是一件困难的工作。让您的应用程序以本机速度运行还可以获得速度优势(因为现在它是本机的)。

在 C++ 或 Delphi 中,您拥有相同的系统,但没有中间的 MSIL 层。因此,如果您使用命名空间或源文件(在 Delphi 下称为单元),那么它会被编译并包含在最终的二进制文件中。因此,您的最终二进制文件将会更大(请阅读:真实应用程序的“正常”大小)。您在 .net 中使用的框架部分也是如此,这些也包含在您的应用程序中。然而,智能链接确实减少了相当多的数量。

希望有帮助!

If I understand you correctly, yes you can, but not under Visual Studio (from what I know).
To force the compiler to generate a real, standalone executable (which means you use C# like any other language) you use the program mkbundle (shipped with Mono). This will compile your C# app into a real, no dependency executable.

There is a lot of misconceptions about this around the internet. It does not defeat the purpose of the .net framework like some people state, because how can you lose future features of the .net framework if you havent used these features to begin with? And when you ship updates to your app, it's not exactly hard work to run it through the mkbundle processor before building your installer. There is also a speed benefit involved making your app run at native speed (because now it IS native).

In C++ or Delphi you have the same system, but without the middle MSIL layer. So if you use a namespace or sourcefile (called a unit under Delphi), then it's compiled and included in your final binary. So your final binary will be larger (Read: "Normal" size for a real app). The same goes for the parts of the framework you use in .net, these are also included in your app. However, smart linking does shave a conciderable amount.

Hope it helps!

等往事风中吹 2024-08-24 16:26:49

发布项目时,您可以将“部署模式”设置为“自包含”,然后选择“生成单个文件”选项。

点击观看 gif 视频

When you publish the project you can set the "Deployment mode" to "Self contained" and then the "Produce single file" option.

click to see the gif video

挽清梦 2024-08-24 16:26:49

我同意@Marlon 的观点。当您使用 Release 配置编译 C# 项目时,您将在项目的“bin/Release”文件夹中找到应用程序的可执行文件。这应该适用于简单的应用程序。

但是,如果您的应用程序对某些外部 dll 有任何依赖项,我建议您使用 VisualStudio 创建一个 SetupProject。这样做,项目向导将找到应用程序的所有依赖项并将它们(库)添加到安装文件夹中。最后,您所要做的就是在用户计算机上运行安装程序并安装您的软件。

I agree with @Marlon. When you compile your C# project with the Release configuration, you will find into the "bin/Release" folder of your project the executable of your application. This SHOULD work for a simple application.

But, if your application have any dependencies on some external dll, I suggest you to create a SetupProject with VisualStudio. Doing so, the project wizard will find all dependencies of your application and add them (the librairies) to the installation folder. Finally, all you will have to do is run the setup on the users computer and install your software.

金橙橙 2024-08-24 16:26:49

我在按原样部署用 C# 制作的小型控制台应用程序时从未遇到过问题。您可能遇到的唯一问题是对 .NET 框架的依赖,但即使这也不应该是一个主要问题。您可以尝试使用该框架的 2.0 版本,该版本应该已经在大多数 PC 上。

使用本机、非托管 C++,您不应该对 .NET 框架有任何依赖,因此您确实应该是安全的。只需获取可执行文件和任何附带文件(如果有)并按原样部署它们;如果您不想安装,则无需安装它们。

I've never had problems with deploying small console application made in C# as-is. The only problem you can bump into would be a dependency on the .NET framework, but even that shouldn't be a major problem. You could try using version 2.0 of the framework, which should already be on most PCs.

Using native, unmanaged C++, you should not have any dependencies on the .NET framework, so you really should be safe. Just grab the executable and any accompanying files (if there are any) and deploy them as they are; there's no need to install them if you don't want to.

枉心 2024-08-24 16:26:49

您可以将所有 dll 嵌入到主 dll 中。请参阅:在已编译的可执行文件中嵌入 DLL

You can embed all dlls in you main dll. See: Embedding DLLs in a compiled executable

安静被遗忘 2024-08-24 16:26:49

我认为不可能按照提问者的要求,通过将所有项目文件合并到一个 .exe 中来避免 dll 地狱。

框架问题是一个转移注意力的问题。出现的问题是,当您有多个项目依赖于一个库时,PITA 可以保持库同步。每次库发生变化时,所有依赖它且未更新的 .exe 都会可怕地死亡。

像一个回答那样告诉人们学习 C 是傲慢和无知的。

I don't think it is possible to do what the questioner asks which is to avoid dll hell by merging all the project files into one .exe.

The framework issue is a red herring. The problem that occurs is that when you have multiple projects depending on one library it is a PITA to keep the libraries in sync. Each time the library changes, all the .exes that depend on it and are not updated will die horribly.

Telling people to learn C as one response did is arrogant and ignorant.

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