5

If I have a basic C# program in Visual Studio such as

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

And I build the project in Visual Studio, I get a .dll instead of a .exe. I've looked in the properties page for the project, and the Output type is set to Console Application. I've tried Windows Application and Class library too but they all create a dll. If it matters, my Target framework is .NET Core 2.0. Not sure what else would be causing this.

Duran Hsieh
  • 926
  • 9
  • 22
  • Try setting the configuration manager in release mode. Also try hitting Ctrl+F5. This would make the program run without debugging. Hopefully the exe would be made under `bin\release\***.exe` – Rishav May 04 '18 at 05:13
  • Yea of course make sure it is a console Application. Something like [this](https://imgur.com/a/Vj27BCG) – Rishav May 04 '18 at 05:16
  • 3
    Possible duplicate of [Build .NET Core console application to output an EXE?](https://stackoverflow.com/questions/44074121/build-net-core-console-application-to-output-an-exe) – SᴇM May 04 '18 at 05:17

2 Answers2

6

You could try following step:

Step 1. Right click project and click publish enter image description here

Step 2. Select folder -> click publish(or create profile, it is ok) enter image description here

Step 3. click configure -> Deployment mode:self-contained -> runtime target:win-x64 -> click save enter image description here

Step 4. click publish, you will find .exe file under your target location enter image description here

Btw, you also see the detail in FolderProfile.pubxml. Hope this helps. :) enter image description here


Update: My environment info:

  1. Visual studio 2017 (15.7.1)
  2. .NET Core 2.0

Duran Hsieh
  • 926
  • 9
  • 22
  • While this works, it doesn't answer why do we need to publish the project, since the build itself should create it, right? Or Dotnet core expect us to run it as DLL? – Avi Dec 10 '20 at 15:14
-1

the aim of .net core is platform independence. Hence a .dll is created. You can call it in a console with dotnet ConsoleApp1.dll.

If you want to have an windows exe, then create a project targeting UWP or .net framework. If you want to create a library with common platform independent code, then I would host all the logic in this .net core dll and create a second project targeting .net framework that just calls into the .net core dll.

gofal3
  • 1,213
  • 10
  • 16