构建 .NET Core 控制台应用程序以输出 EXE

编程入门 行业动态 更新时间:2024-10-10 17:25:17
本文介绍了构建 .NET Core 控制台应用程序以输出 EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对于面向 .NET Core 1.0 的控制台应用程序项目,我无法弄清楚如何在构建期间输出 .exe.该项目在调试中运行良好.

For a console application project targeting .NET Core 1.0, I cannot figure out how to get an .exe to output during build. The project runs fine in debug.

我已经尝试发布该项目,但这也不起作用.这是有道理的,因为 EXE 文件是特定于平台的,但必须有一种方法.我的搜索只找到了对使用 project.json 的旧 .NET Core 版本的引用.

I've tried publishing the project, but that does not work either. It makes sense since an EXE file would be platform-specific, but there must be a way. My searches have only turned up reference to older .NET Core versions that used project.json.

每当我构建或发布时,这就是我所得到的:

Whenever I build or publish, this is all I get:

推荐答案

出于调试目的,您可以使用 DLL 文件.您可以使用 dotnet ConsoleApp2.dll 运行它.如果你想生成一个EXE文件,你必须生成一个自包含的应用程序.

For debugging purposes, you can use the DLL file. You can run it using dotnet ConsoleApp2.dll. If you want to generate an EXE file, you have to generate a self-contained application.

要生成自包含应用程序(Windows 中的 EXE),您必须指定目标运行时(特定于您的目标操作系统).

To generate a self-contained application (EXE in Windows), you must specify the target runtime (which is specific to the operating system you target).

仅限 .NET Core 2.0 之前:首先,在 .csproj 文件中添加目标运行时的运行时标识符(支持的 RID 列表):

Pre-.NET Core 2.0 only: First, add the runtime identifier of the target runtimes in the .csproj file (list of supported RIDs):

<PropertyGroup> <RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers> </PropertyGroup>

从 .NET Core 2.0 开始不再需要上述步骤.

然后,在发布应用程序时设置所需的运行时:

Then, set the desired runtime when you publish your application:

dotnet publish -c Release -r win10-x64 dotnet publish -c Release -r ubuntu.16.10-x64

更多推荐

构建 .NET Core 控制台应用程序以输出 EXE

本文发布于:2023-11-05 02:41:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559690.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制台   应用程序   NET   Core   EXE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!