生成.Net Core作为EXE而不是DLL

编程入门 行业动态 更新时间:2024-10-26 17:35:33
本文介绍了生成.Net Core作为EXE而不是DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将.NET Core项目构建为EXE而不是DLL,以便可以执行。

I want to build a .NET Core project as a EXE and not a DLL so it can be executed.

此处的答案无效:如何运行.Net Core dll?

以下是示例代码:

using System; namespace ConsoleApplication { public class Program { public static void Main(string[] args) { Console.WriteLine("Hello World!"); } } }

这是我的project.json:

{ "version": "1.0.0-*", "compilationOptions": { "emitEntryPoint": true }, "buildOptions": { "debugType": "portable", "emitEntryPoint": true }, "dependencies": {}, "frameworks": { "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "type": "platform", "version": "1.1.0" } }, "imports": "dnxcore50" } } }

我当前正在使用VSCode,每当我使用构建任务来构建项目,或者运行 dotnet restore 时,我都会得到一个 .dll 在我的 bin / Debug 文件夹中。

I'm currently using VSCode, whenever I build the project with the build task, or run dotnet restore I just get a .dll in my bin/Debug folder.

如何构建.NET Core应用程序作为一个exe文件?

How do you build a .NET Core application as an exe?

奖金:我愿意,它将在Mac或其他设备上运行吗?

Bonus: I do, will that run on a mac or other device?

推荐答案

要生成EXE而不是DLL,您需要自包含的部署。您当前正在做的是与框架相关的部署。 要将您的文件转换为自包含文件,请在project.json文件中执行以下步骤。

To produce an EXE instead of a DLL, you need a self-contained deployment. What you are currently doing is a framework-dependent deployment. To convert yours to self-contained, take the following steps in your project.json file.

  • 删除类型:平台 。
  • 添加运行时 部分进行操作应用程序支持的系统。
  • Remove "type": "platform".
  • Add a "runtimes" section for the operating systems your app supports.
  • 构建时,传入目标操作系统。例如。 dotnet build -r osx.10.10-x64 。

    When you build, pass in the target operating system. E.g. dotnet build -r osx.10.10-x64.

    这是生成的project.json

    This is the resultant project.json

    { "version": "1.0.0-*", "compilationOptions": { "emitEntryPoint": true }, "buildOptions": { "debugType": "portable", "emitEntryPoint": true }, "dependencies": {}, "frameworks": { "netcoreapp1.1": { "dependencies": { "Microsoft.NETCore.App": { "version": "1.1.0" } }, "imports": "dnxcore50" } }, "runtimes": { "win10-x64": {}, "osx.10.10-x64": {} } }

    另请参见: docs.microsoft / zh-CN / dotnet / articles / core / deploying /#self-contained-deployments-scd

    更多推荐

    生成.Net Core作为EXE而不是DLL

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

    发布评论

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

    >www.elefans.com

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