构建 .NET Core 控制台应用程序以输出 EXE [英] Build .NET Core console application to output an EXE

查看:52
本文介绍了构建 .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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆