2

I'd imagine this as a massively dumb question but when I build my solution (console app) it creates a dll rather than an executable. Am I doing something wrong or just misunderstanding how this works?

smeel
  • 29
  • 2

4 Answers4

2

Right-click on your project in Solution Explorer and select Properties in the bottom of Context Menu. Select proper Output type then as marked on the screendhot.

enter image description here

As mentioned in another answer here: in case your Target framework is .NET Core, use Publish in the Build menu of Visual Studio width setting Target runtime format, for example win-x86 to make a proper output application format.

Check out the reference: Publish your .NET Core application with Visual Studio

aepot
  • 4,558
  • 2
  • 12
  • 24
  • This assumes that OP's project is framework rather than core. You might want to at least mention that this is a fix for framework. – Code Stranger Feb 24 '20 at 18:49
  • 1
    It would probably be a little more helpful to say something like "Right-click on your project in Solution Explorer" instead of saying "ConsoleApp1". That might not be the name of OP's project. Also, typo on "screenshot". – Broots Waymb Feb 24 '20 at 18:50
  • Thanks for comments. Added `.NET Core` note and fixed "on your project" – aepot Feb 24 '20 at 18:59
1

If this is .Net Framework then more than likely the project output type is set to Class Library in the project properties page.

To fix this you must ensure that you have a method with a signature of static void Main() and set the Output type to Console Application.

To Change the Output Type:

  1. Right click the Project name in the Solution Explorer
  2. Select Properties
  3. On the Application tab change Output Type to Console Application
  4. Change the Startup object drop down to the class that contains your Main method.
  5. Save the Properties and try to build/debug again.
Jeremey Schrack
  • 216
  • 3
  • 3
1

No, that's legit. At least for .NET Core 2.x. For .NET Core 3.x, it does build an .EXE. You could always run it by running: dotnet foo.dll.

So for now, instead of Build, use Publish. That will generate an .EXE.

I typically keep a command handy to just generate it quickly:

dotnet publish -c Release -r win10-x64 --self-contained:false
AngryHacker
  • 59,598
  • 102
  • 325
  • 594
0

Publishing to exe from Visual Studio

Right Click Project > Publish > Configure

  • Select Deployment Mode: Self-Contained

  • Select Preferred Target Runtime

  • Note down the Target location

  • Hit Publish

You will now find your exe in the target location that you made note of

Note: The default option is set to Framework dependant mode, which is why you see the dll file as the output and to run that you can dotnet MyConsoleApp.dll

.NetCore 2.1 / 2.2 / 3.0 (Via Command Line)

.NetCore 3.0 (Via Command Line)

Clint
  • 6,011
  • 1
  • 21
  • 28