question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.NET Core shouldn't use OutputType=Exe/WinExe when it means something else

See original GitHub issue

Spinning off from #1906, .NET Core, by design, currently doesn’t build AnyCPU exes. However, it uses MSBuild syntax that implies otherwise, such as:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net47</TargetFramework>
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

</Project>

In .NET Framework, it made sense to have an OutputType of Library (DLL), Exe (console EXE) or WinExe (non-console EXE), as that directly matched the type of Windows PE produced.

In .NET Core, the output type is always a DLL on Windows (if I understand correctly), which may or may not have code designed to work as an entry point. To eliminate the confusion here, distinct MSBuild syntax could help quite a bit. For example, consider:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <EntryPointType>Console</EntryPointType>
    <TargetFramework>net47</TargetFramework>
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

</Project>

Where EntryPointType is one of: None, Console, NonConsole Or maybe: HasEntryPoint: true/false IsConsoleApplication: true/false

I think this would have led to less surprise in issues like dotnet/cli#6237. (That issue is still useful as a feature request for building an actual .exe on Windows - this one is about the MSBuild contract when producing a .NET Core application with an entry point.)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:11
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
Bartolomeus-649commented, Mar 23, 2020

K.I.S.S!

Developers has been using Microsoft tools to produce code for windows for decades, and there’s an established standard way how stuff work. When things don’t work or behave as the always have, people (including developers) get confused, problems arise and time is wasted trying to figure out what is going on. So, for the tens of millions of developers out there that has been using VS/MsBuild for decades, they get really confused when see a project with the output type set to “Console Application” and the project file contain <OutputType>Exe</OutputType>, and they then end up with a DLL.

  1. Add option to build for Windows
    1. Applications should produce an .exe-file
    2. A library should produce a .dll-file
    3. The project property dialog in VS should clearly and unambiguously reflect the current project
  2. Add an option to build for “dotnet” dll based cross platform
    1. Invent whatever new syntax you want to describe thing in the project file
    2. Produce whatever output you desire
    3. The project property dialog in VS should clearly and unambiguously reflect the current project
4reactions
qwertiecommented, Dec 3, 2020

Yes, or MS could produce a project file with a helpful comment. Communication: it’s necessary™.

<!-- <OutputType>Exe</OutputType> produces a .dll file, but you can run it with dotnet <appname>.dll -->
<OutputType>Exe</OutputType>

P.S. why not use a .exe file extension?

Read more comments on GitHub >

github_iconTop Results From Across the Web

OutputType set to WinExe for WPF and WinForms apps - . ...
NET SDK, when OutputType is set to Exe , it is automatically changed to WinExe for WPF and Windows Forms apps that target...
Read more >
`OutputType` no longer automatically set to WinExe - .NET
Learn about the breaking change in .NET 6 where `OutputType` for WPF and Windows Forms projects is no longer automatically set to `WinExe`....
Read more >
Is it possible to run a .NET Core console application silently ...
NET Core 3.0+, you will be able to set <OutputType>WinExe</OutputType> inside of the csproj file. Currently, this is not directly possible out ......
Read more >
How to Conditionally Target WinExe
NET Core SDK and nothing else. Complexity is the enemy, and I will slay it whenever I can. However, permanently changing my OutputType...
Read more >
Making a tiny .NET Core 3.0 entirely self-contained single ...
NET Core 3.0 SDK's now-built-in Tree Trimmer creates a 13 meg single executable that includes everything it needs to run. C:\Users\scott\Desktop ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found