Sdk: How do I produce an exe for a console application using dotnet build?

Created on 11 Jun 2016  路  15Comments  路  Source: dotnet/sdk

Steps to reproduce

Create a new .Net Core Console Application (PREVIEW).
Run dotnet build from the command line.

Actual behavior

It only produces a .dll

Expected behavior

I need a .exe so I can execute it using the Process class

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview1-002702)

Product Information:
 Version:     1.0.0-preview1-002702
 Commit Sha:  6cde21225e

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.3.9600
 OS Platform: Windows
 RID:         win81-x64

project.json

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}


Most helpful comment

All 15 comments

@Strandedpirate you need to create a self-contained app. For more information, please consult https://dotnet.github.io/docs/core-concepts/app-types.html. When you create a self-contained application, you will get an exe (that is, a binary) and will be able to do what need.

I will go ahead and close this issue. If you still need information, please reopen. Thanks!

That did the trick. Thanks!

Just checking referenced doc, but as of today link is broken

Surely it shouldn't be necessary to deploy a console app as a standalone app simply to invoke it via CreateProcess, as that comes with a lot of overhead and makes it no longer platform independent.

Is it not possible to create the process by spawning the dotnet.exe wth the console app supplied as an argument, and (most importantly) will the standard input and output function correctly if the process is created this way?

Answer to my last question is yes.

Reference docs show setting the OutputType in the csproj as exe, building still outputs a dll anyways :|

To produce an exe, you need to publish your application as a self-contained app targeting a runtime that uses exes (windows).

For instance, run dotnet publish -r win10-x64 and you should get a publish folder and under it you will have a exe.

Notice that if you are not using the latest CLI, then you also need to add a <RuntimeIdentifier>win10-x64</RuntimeIdentifier> to your project and run dotnet restore before the publish.

@livarcocc How do you do this in Visual Studio 2017 preferably in the GUI using the project properties?

I added that RuntimeIdentifier to my CSProj file manually under the TargetFramework and ran that command you stated and I get nothing but errors about Assets file X doesn't have a target for X. So it looks like if your supporting libraries do not have the same RunTimeIdentifieers all the way through your dependencies you are screwed.

I am not sure why this is so hard. This seems like it should be as easy as it was with the full framework.

I am not sure which version of the tools you are using, but you need to run dotnet restore (depending on your version of the CLI) after adding the runtimeidentifier, so that nuget can go and get the native assets for the runtime you specified.

it is the latest VS2017 update 2 and what it has.
I figured it out from the command line, you do not need to change your project file at all. You just go to the folder with the project in question then run these two commands.

dotnet restore -r win10-x64

dotnet publish -c Release -r win10-x64

Then it built just fine without modifications to the CSProj file. The only thing missing is the ability to publish from VS2017 UI for any supported runtimes, and for self-contained to be supported as well.

This should not be closed @6237 https://github.com/dotnet/cli/issues/6237

When I run

dotnet restore -r win10-x64

dotnet publish -c Release -r win10-x64

I still get a dll and not an exe

@SteveScott where are you looking for the exe? It should be under `/bin/Release/netcoreapp2.0/win10-x64/publish/'. There should be a .exe under that folder.

The following code correctly generated the EXE:

dotnet.exe publish -c Release -r win-x64 -f netcoreapp2.0

Was this page helpful?
0 / 5 - 0 ratings