如何运行.Net Core dll?

我在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中)或其他平台上的可执行文件。

编辑:30/01/2017

这已经不够了。 您现在可以在此处所述的依赖于框架的部署和自包含部署之间进行操作。

简写:

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

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

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

  • 从project.json中删除"type": "platform"
  • 将runtimes部分添加到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": {} } }