c# - 如何运行 .Net Core dll?

标签 c# .net-core

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

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

代码是:

using System;

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

最佳答案

将此添加到您的 project.json 文件中:

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

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

编辑:2017 年 1 月 30 日

这还不够。您现在可以在依赖于框架的部署和自包含部署之间进行选择,如所述here .

缩写形式:

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

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

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

  • 从 project.json 中删除 "type": "platform"
  • 将运行时部分添加到 project.json
  • 使用目标操作系统构建 dotnet build -r win7-x64
  • 运行生成的 MyApp.exe

project.json 文件:

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

关于c# - 如何运行 .Net Core dll?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36516848/

相关文章:

c# - 在窗口应用程序中使用数据表或数据集在gridview中添加进度条

postgresql - 通过 npgsql 使用 ca 证书连接到 .NET Core 上的 DO Postgres 集群

.net - .NET Core 中没有 AppDomain!为什么?

c# - 如何从我的应用程序处理 SQL 键值表?

c# - DataGridView 处理列重新排序事件

C#:映射 IDataReader.GetTableSchema() 和 DbType 枚举?

c# - Windows 服务中的模拟

.net-core - 我可以缩小 dotnet 发布包吗

c# - 如何在类/独立线程 ASP.Net Core 中使用 ApplicationDbContext

c# - 在 .NET Core 2.1 中安装 .NET SQL Client 后,DbProviderFactories.GetFactoryClasses 不返回任何结果