如何运行.Net Core dll? [英] How to run a .Net Core dll?

查看:104
本文介绍了如何运行.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 上生成 MyApp.exe(在 bin/Debug 中)或其他平台上的可执行文件.

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

30/01/2017

这已经不够了.您现在可以按照 这里.

It is not enough anymore. You now have the possibility between Framework-dependent deployment and Self-contained deployment as described here.

简称:

依赖于框架的部署(.net core 存在于目标系统上)

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

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

自包含部署(包括.net core运行时在内的所有组件都包含在应用程序中)

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

  • 从 project.json 中删除 "type": "platform"
  • 将运行时部分添加到 project.json
  • 使用目标操作系统构建dotnet build -r win7-x64
  • 运行生成的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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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