Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
179 views
in Technique[技术] by (71.8m points)

c# - How to run a .Net Core dll?

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

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

The code is:

using System;

class Program
{
    public static void Main()
    {
        Console.WriteLine("Hello from Mac");        
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Add this to your project.json file:

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

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

Edit: 30/01/2017

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

Short form:

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

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

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

  • 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 file:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...