我想将.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.
构建时,传入目标操作系统。例如。 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
发布评论