smeel
smeel

Reputation: 49

Visual Studio project builds into dll rather than executable

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?

Upvotes: 4

Views: 4395

Answers (4)

Clint
Clint

Reputation: 6509

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)

Upvotes: 1

aepot
aepot

Reputation: 4824

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

Upvotes: 2

AngryHacker
AngryHacker

Reputation: 61636

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

Upvotes: 1

Jeremey Schrack
Jeremey Schrack

Reputation: 276

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.

Upvotes: 1

Related Questions