Reputation: 1640
Why, when I create a .NET Core Console Application project in Visual Studio 2017, does it output a DLL file instead of an EXE file?
Well, we know the answer to this and it's been well documented and addressed in other, very popular questions on Stack Overflow.
I was frustrated by the amount of hoops to jump through in the other answers.
So, is there a simpler way to generate an EXE file?
Upvotes: 2
Views: 5627
Reputation: 1640
Well, this is what I came up with.
I decided to write this as its own question and answer, as technically this isn't an answer to the question, "How do I create a .NET Core EXE file?"
A .NET Core portable application is a DLL file and you launch it with dotnet yourapp.dll
, unless it's a self contained deployment, in which case you launch it with yourapp.exe
on Windows or ./yourapp
on Linux.
This method does not try to solve that or change it.
The documentation for that is here: .NET Core application publishing overview
I've been learning how to support the new (.NET Core and Standard) and the old (.NET Framework) at the same time.
It's now become really simple.
Here's the smallest yourapp.csproj
file for the .NET SDK:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
</Project>
This spits out yourapp.dll
.
But, if you change it to:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp2.0;net451</TargetFrameworks>
</PropertyGroup>
</Project>
(Note the change from <TargetFramework>
to <TargetFrameworks>
!)
Now, when you build, in the output directory there is a net451
and a netcoreapp2.0
directories. In netcoreapp2.0
there is the portable dll
application. In the net451
there is a normal, full framework, console exe
.
Obviously it's not portable, but neither is the Windows EXE file created by the other methods. If you absolutely need a Windows EXE file targeting .NET Core, use the method linked at the top of the article. Of course you can use both, that's the great thing about the TargetFrameworks
node.
Here's a Stack Overflow question which has more information about creating real .NET Core EXE files:
VS2017 Compile NetCoreApp as EXE
Upvotes: 3