Sdk: OutputType Exe does not lead to .exe in output

Created on 5 Jun 2017  路  4Comments  路  Source: dotnet/sdk

Steps to reproduce

  1. Install dotnetcore2 preview 1 (2.0.0-preview1-005977)
  2. Create a project directory and go into it(I'm using PowerShell):
    md DotNetCore2ConsoleExe
    sl DotNetCore2ConsoleExe
  3. Create a new console project
    dotnet new console
  4. Check that the csproj file OutputType setting is set to Exe:
gc .\DotNetCore2ConsoleExe.csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

</Project>
  1. Build the project:
 dotnet build
Microsoft (R) Build Engine version 15.3.117.23532
Copyright (C) Microsoft Corporation. All rights reserved.

  DotNetCore2ConsoleExe -> C:\Source\Repos\Rulers\DotNetCore2ConsoleExe\bin\Debug\netcoreapp2.0\DotNetCore2ConsoleExe.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.43

Expected behavior

Output should be executable (DotNetCore2ConsoleExe.exe)

Actual behavior

Output was a DLL (DotNetCore2ConsoleExe.dll)

Environment data

dotnet --info output:

.NET Command Line Tools (2.0.0-preview1-005977)

Product Information:
 Version:            2.0.0-preview1-005977
 Commit SHA-1 hash:  414cab8a0b

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.0-preview1-005977\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0-preview1-002111-00
  Build    : 1ff021936263d492539399688f46fd3827169983

Most helpful comment

@zunder It's not really "fixed." Read that thread: dotnet/sdk#8065 - it's apparently a "by design" feature, although I personally think the design ought to change. After all, every OS has the concept of an executable binary. However, the thing I needed most was to get the exit code from my static int Main(args[]), and I was able to do that, even by calling dotnet.exe and having it run my (ahem) "executable" DLL.

Apparently (not that I've tried this) -- the way to actually get the .exe file (for Windows, for example) is to publish the project and create a "self-contained deployment" (https://docs.microsoft.com/en-us/dotnet/core/deploying/index#self-contained-deployments-scd)

All 4 comments

BTW, I read this: https://github.com/dotnet/cli/issues/6237
And, yeah, considering you have millions of .NET Framework developers new to .NET Core who know all about Windows .exe files and not that much about macOS and *nix, calling it an Exe when what you mean is "library that has a standard Main" is misleading to say the least. Call it "app" or something.

@CodeCharm How did you fix this issue for you? I am still hopelessly trying to generate an .exe and all I get is a .dll.

@zunder It's not really "fixed." Read that thread: dotnet/sdk#8065 - it's apparently a "by design" feature, although I personally think the design ought to change. After all, every OS has the concept of an executable binary. However, the thing I needed most was to get the exit code from my static int Main(args[]), and I was able to do that, even by calling dotnet.exe and having it run my (ahem) "executable" DLL.

Apparently (not that I've tried this) -- the way to actually get the .exe file (for Windows, for example) is to publish the project and create a "self-contained deployment" (https://docs.microsoft.com/en-us/dotnet/core/deploying/index#self-contained-deployments-scd)

And you have to love what happens if you try to run it.

C:\Dev\software\Bin\Debug\netcoreapp2.1>software.dll

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

C:\Dev\software\Bin\Debug\netcoreapp2.1>dotnet software.dll
Hello, World!
Was this page helpful?
0 / 5 - 0 ratings

Related issues

natemcmaster picture natemcmaster  路  58Comments

NinoFloris picture NinoFloris  路  99Comments

murali2020kris picture murali2020kris  路  70Comments

davkean picture davkean  路  163Comments

danmosemsft picture danmosemsft  路  137Comments