Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build .Net Core as an EXE not a DLL

Tags:

c#

.net-core

dll

I want to build a .NET Core project as a EXE and not a DLL so it can be executed.

The answer here did not work: How to run a .Net Core dll?

Here is the sample code:

using System;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Here is my project.json:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50"
    }
  }
}

I'm currently using VSCode, whenever I build the project with the build task, or run dotnet restore I just get a .dll in my bin/Debug folder.

How do you build a .NET Core application as an exe?

Bonus: I do, will that run on a mac or other device?

like image 436
Douglas Gaskell Avatar asked Jan 17 '17 19:01

Douglas Gaskell


People also ask

How do I create an EXE for .NET Core console application?

First, right-click on the project and then hit Publish, then select folder and click create. Click the edit button to edit the configuration. In the publish configuration you can check the single EXE option.

Can we convert dll to EXE?

DLL to EXE is an Open Source, portable, Command Prompt utility that can convert any DLL to an EXE (executable). If you execute DLL to EXE without first being in the Command Prompt or Powershell, you will be shown the arguments required. Simply put, type in "dll_to_exe filename.

Is .NET Core discontinued?

NET Core v. Next ,” as Microsoft describes it). That said, Microsoft will end long-term support for the most recent release of Core (3.1. 7) around December 2022 and has just announced that .


2 Answers

I think most people got to this page because they picked .net core and they can't get an executable .exe file from their VS 2017 build. vs 2015 always used to make a .exe file for a console application. Suddenly vs 2017 is fussing over this simple task. With vs 2017 when you create the project you get 2 choices for a Console application. One is Console App (.NET Core) and the other choice is Console App (.NET Framework). If you pick the .NET Core option you are going to have to move heaven and earth to get a .exe file from your Build. The (.NET Core) option creates a .dll file from a Build. If you pick the (.NET Framework) option it will build a xxxx.exe executable for you by default.

like image 68
renaissanceMan Avatar answered Sep 29 '22 14:09

renaissanceMan


To produce an EXE instead of a DLL, you need a self-contained deployment. What you are currently doing is a framework-dependent deployment. To convert yours to self-contained, take the following steps in your project.json file.

  1. Remove "type": "platform".
  2. Add a "runtimes" section for the operating systems your app supports.

When you build, pass in the target operating system. E.g. dotnet build -r osx.10.10-x64.

This is the resultant project.json

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true
  },
  "dependencies": {},
  "frameworks": {
    "netcoreapp1.1": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "version": "1.1.0"
        }
      },
      "imports": "dnxcore50"
    }
  },
  "runtimes": {
    "win10-x64": {},
    "osx.10.10-x64": {}
  }
}

See also: https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/#self-contained-deployments-scd

like image 24
Shaun Luttin Avatar answered Sep 29 '22 12:09

Shaun Luttin