简体   繁体   English

如何使用 Windows Forms 从 C# 创建 EXE 文件?

[英]How do I create an EXE file from C# using Windows Forms?

I have a simple Windows Forms project in C#.我在 C# 中有一个简单的 Windows Forms 项目。

I want to be able to turn this into an EXE file to be able to give this out to some of my friends.我希望能够将其转换为 EXE 文件,以便能够将其提供给我的一些朋友。 I am using Visual Studio 2019.我正在使用 Visual Studio 2019。

Before you say that there is an application file in the bin/debug folder, yes, I know that.在你说 bin/debug 文件夹中有一个应用程序文件之前,是的,我知道。 The thing is that I want to be able to create this into just one file where they won't be able to access the code.问题是我希望能够将其创建到一个他们将无法访问代码的文件中。

If you want a 100% portable application:如果您想要一个 100% 可移植的应用程序:

  1. Install the Nuget Package Costura.Fody .安装 Nuget Package Costura.Fody It will add all the dependencies directly into the.exe so that there are no separate.dlls or other files apart from it.它将所有依赖项直接添加到.exe 中,这样就没有单独的.dll 或除此之外的其他文件。

    哥斯图拉

  2. Change the output to Release and generate your project (run it or CTRL + B)将 output 更改为Release并生成您的项目(运行它或 CTRL + B)

    发布

  3. Go to your project folder / bin / release and there is the .exe Go 到您的project folder / bin / release并且有.exe

  4. Profit.利润。

Right click on your project in Solution Explorer, then Publish ... If it is.Net Core project, you'll get your .exe in the indicated folder.在解决方案资源管理器中右键单击您的项目,然后发布...如果是 .Net Core 项目,您将在指定文件夹中获得 .exe。 You can also chceck folder: ProjectName/bin/Debug(or Release)/netcoreapp(or netframework)/ .exe should be there.您还可以检查文件夹: ProjectName/bin/Debug(或 Release)/netcoreapp(或 netframework)/ .exe 应该在那里。

You may be interested in this link: https://docs.microsoft.com/en-us/visualstudio/deployment/publish-overview?view=vs-2022您可能对此链接感兴趣: https://docs.microsoft.com/en-us/visualstudio/deployment/publish-overview?view=vs-2022

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM