C# 无需安装 .NET 框架即可创建独立的 exe

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16708103/
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-08-10 01:43:35  来源:igfitidea点击:

Create a standalone exe without the need to install .NET framework

c#visual-studio-2010exe.net-framework-version

提问by Charlotte Vancraeynest

I'm a student and at the moment i'm doing an internship at a company. This internship is about analysing a project. For this project I have made a demo to show to the Marketing director. The demo I have made is a simple project created in Visual Studio 2010 in c# with Windows Forms and a connection to an Access database.

我是一名学生,目前正在一家公司实习。这个实习是关于分析一个项目。对于这个项目,我制作了一个演示来展示给营销总监。我所做的演示是在 Visual Studio 2010 中使用 Windows 窗体和 Access 数据库连接在 c# 中创建的一个简单项目。

So now i have to show this demo to this director in a presentation but after this presentation the director wants the project on his computer so he can try and use it. The problem is now that the computers here in this company don't have .NET framework 4.0 and the computers are so protected over here that we can't install anything new. To install something you have to go through a procedure that takes weeks.

所以现在我必须在演示中向这位导演展示这个演示,但是在这个演示之后,导演想要在他的电脑上使用这个项目,这样他就可以尝试使用它。现在的问题是,这家公司的计算机没有 .NET Framework 4.0,而且这里的计算机受到如此保护,我们无法安装任何新的东西。要安装某些东西,您必须经过一个需要数周时间的过程。

I have looked al over the internet but all i find is how to install the .NET framework.

我已经浏览了互联网,但我发现的只是如何安装 .NET 框架。

Is there any possible way that I can create an standalone exe without the need to install .NET framework? Please help!

有没有什么可能的方法可以创建独立的 exe 而无需安装 .NET 框架?请帮忙!

采纳答案by Carlos Landeras

If you want to execute an application that is developed using Net Framework 4, you will need to have installed .Net Framework 4 on client computer.

如果要执行使用 Net Framework 4 开发的应用程序,则需要在客户端计算机上安装 .Net Framework 4。

Your application is compiled in CIL (Common Intermediate Language), so it needs to be interpreted by the framework engine.

您的应用程序是用 CIL(通用中间语言)编译的,因此它需要由框架引擎解释。

It is the same if you want to execute a Java program. You will have to install the Java Machine.

如果要执行 Java 程序也是一样。您必须安装 Java 机器。

The only way you don't need to install frameworks is programming native applications with C, C++.

您不需要安装框架的唯一方法是使用 C、C++ 编写本机应用程序。

回答by bytecode77

You can't build a C# executable without .NET Framework. Even if some resources indicate that you can, that only works in theory.

如果没有 .NET Framework,您将无法构建 C# 可执行文件。即使某些资源表明您可以,这也仅在理论上有效。

But you could use an older version of .NET Framework like .NET 4.0. If this doesn't work for you, you have to choose a language like C++ which doesn't require CLR at all.

但是您可以使用旧版本的 .NET Framework,例如 .NET 4.0。如果这对您不起作用,您必须选择一种完全不需要 CLR 的语言,如 C++。

Update 2018:

2018 年更新:

Do not target .NET 2.0 or 3.5. It's not compatible with the 4.x version. However, .NET 4.0 targeted binaries work with .NET Framework 4.0, 4.5, 4.6, 4.7 and so on. So to reach maximum compatibility, compile with .NET 4.0. You will have to accept that some features will not be available, however, your binary will run virtually anywhere.

不要以 .NET 2.0 或 3.5 为目标。它与 4.x 版本不兼容。但是,面向 .NET 4.0 的二进制文件适用于 .NET Framework 4.0、4.5、4.6、4.7 等。因此,要达到最大兼容性,请使用.NET 4.0 进行编译。您将不得不接受某些功能将不可用,但是,您的二进制文件几乎可以在任何地方运行。

(2018: By now, .NET 2.0 - 3.5 has much lower distribution than 4.x)

(2018 年:到目前为止,.NET 2.0 - 3.5 的分布比 4.x 低得多)

回答by LEONARDO A LINDEN

Delphi is your solution, deploy native bin executables

Delphi 是您的解决方案,部署本机 bin 可执行文件

回答by PeterFnet

C# now supports this with .NET Native.

C# 现在通过 .NET Native 支持这一点。

Instead of compiling to intermediate language, it will compile to native code and run with statically linked .NET libraries. Therefore, there will be no .Net Runtime requirements for end-users.

它将编译为本机代码并使用静态链接的 .NET 库运行,而不是编译为中间语言。因此,最终用户将没有 .Net Runtime 要求。

https://msdn.microsoft.com/en-us/vstudio/dn642499.aspx

https://msdn.microsoft.com/en-us/vstudio/dn642499.aspx

https://msdn.microsoft.com/en-us/library/dn584397(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/dn584397(v=vs.110).aspx

Only works for Windows 10

仅适用于 Windows 10

回答by BytePhoenix

To be honest, it really isnt a problem nowadays. the .NET framework is found on almost every single computer nowadays, and you can even make a installer with Advanced Installer that silently install the .NET framework on your computer when you are installing the programme.

老实说,现在这真的不是问题。.NET 框架现在几乎可以在每台计算机上找到,您甚至可以使用 Advanced Installer 制作安装程序,在安装程序时在您的计算机上静默安装 .NET 框架。

回答by dns

You can use Mono and statically link you program, so your program don't need .NET CLR runtime and act as standalone program.

您可以使用 Mono 并静态链接您的程序,因此您的程序不需要 .NET CLR 运行时并充当独立程序。

Mono Project

单声道项目

回答by Andrew

YES, THIS IS POSSIBLE!

是的,这是可能的!

At least 3 ways exist:

至少存在3种方式:

1.you can check all OSes that you planning to run your app and build with such version of .NET. As Windows have a built-in framework libs.

1.您可以检查您计划运行应用程序的所有操作系统,并使用此类版本的 .NET 构建。由于 Windows 有一个内置的框架库。

Vista -.NET v3.0 -- All service packs

Windows 7 - .NET v3.5 -- All versions and service packs

Windows 8 - .NET v4.0 [Best choice if you are not sure]

Windows 8.1 - .Net v4.5

Windows 10 - .Net v4.6

Vista -.NET v3.0 -- 所有服务包

Windows 7 - .NET v3.5 -- 所有版本和服务包

Windows 8 - .NET v4.0 [不确定时的最佳选择]

Windows 8.1 - .Net v4.5

Windows 10 - .Net v4.6

as they are already pre-installed by default -- no extra install will be needed.

因为默认情况下它们已经预先安装 - 不需要额外安装。



2.You can compile it into native code (but not into CIL)with ".NET Native". This is means that there are no .Net Framework will be needed for apps.

2.您可以使用“.NET Native”将其编译为本机代码(但不能编译为CIL)。这意味着应用程序不需要 .Net Framework。

But looks like it works only with Windows 10.

但看起来它只适用于 Windows 10。



3.There is Turbo Studio(earlier Spoonand earlier XenoCode) that can wrap everything that your app needs and runs it in as a standalone.

3.有涡轮工作室(早先勺子和更早XenoCode),它可以包含你的应用需求,并运行它作为一个独立的一切。

From their site:

从他们的网站:

Turbo Studio

Run .NET Without .NET. Easily embed runtime dependencies such as .NET, Java, and SQL directly into virtual applications. Launch reliably on any desktop, regardless of underlying component installs.

涡轮工作室

在没有 .NET 的情况下运行 .NET。轻松地将 .NET、Java 和 SQL 等运行时依赖项直接嵌入到虚拟应用程序中。无论底层组件安装如何,都可以在任何桌面上可靠地启动。