本文介绍了如何运行.Net Core dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Mac上使用 dnu build 命令构建了控制台应用程序。输出为 MyApp.dll

I've build my console application using dnu build command on my Mac. The output is MyApp.dll.

因为它不是 MyApp.exe ,如何在Windows甚至Mac上执行它?

As it is not MyApp.exe, how can I execute it on windows, or even on Mac?

代码为:

using System;

class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello from Mac");
    }
}


推荐答案

添加这到您的project.json文件:

Add this to your project.json file:

 "compilationOptions": {
        "emitEntryPoint": true
 },

它将在Windows(在bin / Debug中)或可执行文件中生成MyApp.exe。在其他平台上。

It will generate the MyApp.exe on Windows (in bin/Debug) or the executable files on other platforms.

编辑:30/01/2017

它是不够了。如。

简短形式:

与框架相关的部署 >(目标系统中存在.net核心)

Framework-dependent deployment (.net core is present on the target system)


  • 使用dotnet命令行实用程序 dotnet运行dll MyApp.dll

  • Run the dll with the dotnet command line utility dotnet MyApp.dll

自包含部署(所有组件均包括.net核心运行时包含在应用程序中)

Self-contained deployment (all components including .net core runtime are included in application)


  • 删除 type: platform 从project.json

  • 将运行时部分添加到project.json

  • 使用目标操作系统进行构建 dotnet build -r win7- x64

  • 运行生成的 MyApp.exe

  • Remove "type": "platform" from project.json
  • Add runtimes section to project.json
  • Build with target operating system dotnet build -r win7-x64
  • Run generated MyApp.exe

project.json文件:

project.json file:

{
    "version": "1.0.0-*",
    "buildOptions": {
        "emitEntryPoint": true
    },
    "frameworks": {
        "netcoreapp1.0": {
            "dependencies": {
                "Microsoft.NETCore.App": {
                    "version": "1.0.1"
                }
            }
        }
    },
    "imports": "dnxcore50",
    "runtimes": { "win7-x64": {} }
}

这篇关于如何运行.Net Core dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 05:56