如何使 Vb.net 文件/程序独立于 .Exe
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17130995/
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
How to make a Vb.net file/program To Standalone .Exe
提问by 1478963
I have a project done in VB.NET and I want to publish it for distribution. I know that when I build solution It creates an .Exe. But that requires local resorouces. If I build for release I know it works but it still needs the .Net platform installed. Is there anyway to make a true standalone .exe or something that would run on a persons computer if they do not have .NET installed. Also the ClickOnce application thing is not a wanted Solution.
我有一个在 VB.NET 中完成的项目,我想发布它以进行分发。我知道当我构建解决方案时,它会创建一个 .Exe。但这需要本地资源。如果我为发布而构建,我知道它可以工作,但它仍然需要安装 .Net 平台。无论如何,如果他们没有安装.NET,是否可以制作真正的独立.exe或可以在个人计算机上运行的东西。此外,ClickOnce 应用程序并不是想要的解决方案。
Is there any converter program that can do this for me?
是否有任何转换器程序可以为我做到这一点?
回答by varocarbas
The .NET framework represents the basic prerequisite to run a .NET program; equivalently than having Windows installed is the prerequisite to run a Windows program. Bear in mind that any Windows version includes the .NET framework (and, actually, it tends to involve top-priority updates and thus are automatically perfomed by Windows Update in many cases). A big proportion of the programs running on Windows created during the last 10 years are built on the .NET framework; a relevant proportion of the sites (like this one, for instance) are built on ASP.NET and thus the given server has to include the .NET framework. If overall compatility is a concern for you, you might rely on a-bit-old .NET version: the latest one in VS 2010 (4.0) should be fine for most of modern computers; but you can even rely on the previous one (3.5) to be completely sure. Lastly, bear in mind that a .NET program can also be run under a OS other than Windows (Linux or MacOS, for example); although, from my past experiences, these are not too reliable situations. Nonetheless, in case of being interested in other OS, you should do some research/testing on this front to see if the available options offer what you are looking for.
.NET 框架代表了运行 .NET 程序的基本先决条件;相当于安装 Windows 是运行 Windows 程序的先决条件。请记住,任何 Windows 版本都包含 .NET 框架(实际上,它往往涉及最高优先级的更新,因此在许多情况下由 Windows 更新自动执行)。过去 10 年中创建的在 Windows 上运行的大部分程序都是基于 .NET 框架构建的;相关比例的站点(例如这个站点)是建立在 ASP.NET 上的,因此给定的服务器必须包含 .NET 框架。如果您关心整体兼容性,您可能会依赖有点旧的 .NET 版本:VS 2010 (4.0) 中的最新版本对于大多数现代计算机应该没问题;但您甚至可以依靠前一个 (3.5) 来完全确定。最后,请记住,.NET 程序也可以在 Windows 以外的操作系统(例如 Linux 或 MacOS)下运行;虽然,根据我过去的经验,这些不是太可靠的情况。尽管如此,如果对其他操作系统感兴趣,您应该在这方面进行一些研究/测试,以查看可用选项是否提供您正在寻找的内容。
SUMMARY: the exe file generated by the Visual Studio is actually what you call "standalone .exe". One of its defining features is the .NET version (which can be changed in the Project Settings); a program can only be run on computers with a .NET framework (or equivalent) equal or newer than the one on which it was built. The 4.0 version should be OK for most of new/properly-updated computers; the 3.5 .NET would work with virtually any computer (although, logically, it includes less features than the 4.0 one).
总结:Visual Studio 生成的exe文件其实就是你所说的“独立的.exe”。它的定义特性之一是 .NET 版本(可以在项目设置中更改);程序只能在具有 .NET 框架(或等效框架)的计算机上运行,该框架与构建它的框架相同或更新。4.0 版本对于大多数新的/正确更新的计算机应该是可以的;3.5 .NET 几乎适用于任何计算机(尽管从逻辑上讲,它包含的功能少于 4.0 的)。
---------------------------- UPDATE AFTER COMMENTS --------------------
--------------------------- 评论后更新 ------------------- ——
From some comments, I have undertood that my statement wasn't as clear as I thought and this is the reason for this update
从一些评论中,我明白我的陈述并不像我想象的那么清楚,这就是这次更新的原因
.NET is pre-installed in Windows only since Vista. XP does not include the .NET runtime by default. The reason for not having mentioned this issue in my answer was that having a XP Windows without .NET is highly unlikely. Firstly because this is a top-priority, automatic update and thus one of the first times the computer is connected to internet "Windows Update" will take care of this. And secondly because this is the basic framework for any Microsoft programming over the last 10 years and thus a Windows computer not having it will not be able to run almost anything. With this last sentence, I don't mind that most of the programs are built on .NET, but that for a Windows-based environment most of nowadays basic requirements do include .NET.
It was also pointed out that there is some compatibility problems between different .NET versions (that various side-by-side versions were required). The basic Microsoft approach to the different .NET versions is backwards compatibility, what means that a given .NET version can run any program built with that version or older. This is theoretically right, but not always right in fact. My approach to this problem is relying on a bit old .NET version (3.5) and not using too new/untested features (e.g., WPF). If you want a for-sure overall compatible program you should work quite a lot on this front (compatibility between versions is one of most typical problem of any programming platform), instead expecting Microsoft to take care of everything. Thus, in principle, just one .NET version (the last one) has to be installed (which, on the other hand, is not the case for a big proportion of computers; for example: computer including the 3.5 version being updated, over the years, to 4.0 and 4.5 by maintaining the previous versions).
Lastly, I want to highlight that my intention with this answer is not defending any programming approach over any other one; I am just describing what is there from the point of view of your question "can I remove the .NET part?" -> no, you cannot; there is no (sensible) way to do that. If you want to rely on a different programming platform you should get informed about it (I am sure that Camilo Martin will be more than happy to help you on this front). If you prefer to rely on .NET, be sure that you can generate an overall compatible program (to be run on Windows).
.NET 仅从 Vista 开始预安装在 Windows 中。默认情况下,XP 不包括 .NET 运行时。在我的回答中没有提到这个问题的原因是非常不可能拥有没有 .NET 的 XP Windows。首先,因为这是最高优先级的自动更新,因此计算机首次连接到互联网时,“Windows 更新”将处理此问题。其次,因为这是过去 10 年来任何 Microsoft 编程的基本框架,因此没有它的 Windows 计算机将无法运行几乎任何东西。最后一句话,我不介意大多数程序是建立在 .NET 上的,但是对于基于 Windows 的环境,现在大多数基本要求确实包括 .NET。
也有人指出,不同的 .NET 版本之间存在一些兼容性问题(需要各种并行版本)。Microsoft 对不同 .NET 版本的基本方法是向后兼容,这意味着给定的 .NET 版本可以运行使用该版本或更早版本构建的任何程序。这在理论上是正确的,但实际上并不总是正确的。我解决这个问题的方法是依赖有点旧的 .NET 版本 (3.5),而不是使用太新/未经测试的功能(例如,WPF)。如果你想要一个完全兼容的程序,你应该在这方面做很多工作(版本之间的兼容性是任何编程平台最典型的问题之一),而不是期望微软处理一切。因此,原则上,只需要安装一个 .NET 版本(最后一个)(另一方面,大部分计算机的情况并非如此;例如:包括 3.5 版本的计算机,多年来通过维护以前的版本更新到 4.0 和 4.5)。
最后,我想强调的是,我对这个答案的意图并不是捍卫任何一种编程方法;我只是从您的问题“我可以删除 .NET 部分吗?”的角度来描述那里有什么?-> 不,你不能;没有(明智的)方法可以做到这一点。如果你想依赖不同的编程平台,你应该了解它(我相信 Camilo Martin 会非常乐意在这方面帮助你)。如果您更喜欢依赖 .NET,请确保您可以生成一个整体兼容的程序(在 Windows 上运行)。
回答by user8411732
Easy way to convert in .exe in VB.NET-2010:
在 VB.NET-2010 中转换 .exe 的简单方法:
Create New Project
Select Windows Application And Save Proper Path
Comple Project then Select File-> Save All
Select Build->Start Build
创建新项目
选择 Windows 应用程序并保存正确的路径
完成项目然后选择文件-> 全部保存
选择构建->开始构建
Your Project .exe Created Your Project Save Path:
您的项目 .exe 创建了您的项目保存路径:
Select Windows Application 1
Select bin Folder
Select Debug Folder
选择 Windows 应用程序 1
选择 bin 文件夹
选择调试文件夹
And in Debug folder your .exe File is ready.
在 Debug 文件夹中,您的 .exe 文件已准备就绪。
回答by user8411732
Quick Basic once made and executable (.exe) directly form their VB code, but I wouldn't recommend converting to Quick Basic. You can look at Mono to see if they have anything yet. (mono allows you to use compiled vb.net in other operating systems).
Quick Basic 曾经制作和可执行 (.exe) 直接形成他们的 VB 代码,但我不建议转换为 Quick Basic。您可以查看 Mono 以查看它们是否还有任何东西。(mono 允许您在其他操作系统中使用已编译的 vb.net)。
Ezirit Reactor makes a single executable, but it's not free.
Ezirit Reactor 制作单个可执行文件,但它不是免费的。
You can bundle .NET Framework into your distribution so that users don't have download it.
您可以将 .NET Framework 捆绑到您的发行版中,这样用户就不必下载它。
Why do you need an executable (.exe)? If the reason is for security and to minimize chances of reverse engineering, then get a good obfuscator.
为什么需要可执行文件 (.exe)?如果原因是为了安全和尽量减少逆向工程的机会,那么请使用一个好的混淆器。