1

I am very confused because I created a new project in Visual Studio 2019. I have tried this three separate times with different projects, and each time it exports as a DLL instead of an EXE. Here are the steps to reproduce this problem:

  1. New project
  2. Console App (.NET Core)
  3. Set details for new project, and hit the "Create" button
  4. Add Microsoft.Win32.Registry NuGet package to project
  5. Add the following code:
using Microsoft.Win32;
using System;

namespace Key_Statistics_Startup_Changer {
    class Program {
        static void Main(string[] args) {
            if (args[0] == "CREATE_STARTUP") {
                RegistryKey rkey = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                rkey.SetValue("Key Statistics", @"C:\Program Files\Key Statistics\Key Statistics.exe");
            }
            else if (args[0] == "REMOVE_STARTUP") {
                RegistryKey rkey = Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                rkey.DeleteValue("Key Statistics");
            }
        }
    }
}
  1. Build and run project

When I do this, the program does create or remove the desired registry from startup (what the code is trying to accomplish), when I input arguments through Visual Studio. However, when this project is built, my Key Statistics Startup Changer\bin\Debug folder gives me a sub-directory netcoreapp2.1 with the following files:

Key Statistics Startup Changer.deps.json
Key Statistics Startup Changer.dll
Key Statistics Startup Changer.pdb
Key Statistics Startup Changer.runtimeconfig.dev.json
Key Statistics Startup Changer.runtimeconfig.json

I am positive that I have the right folder where it would export, and every time I re-create the steps (making sure I don't select C# DLL project), this happens.

What's the deal here?

P tray
  • 83
  • 1
  • 3
  • 3
    Possible duplicate of [Build .Net Core as an EXE not a DLL](https://stackoverflow.com/questions/41705465/build-net-core-as-an-exe-not-a-dll) – Diado May 08 '19 at 15:22

3 Answers3

2

You went wrong when you chose Console App (.NET Core) instead of Console App (.NET Framework) , In a nutshell, it's harder getting a .exe from .net core than .net framework.

No worries though, you can simply copy all your code and paste them in a new Console App (.NET Framework) project.

Sadra M.
  • 1,304
  • 1
  • 17
  • 28
1

Right click on the project and go to properties. Choose the Application tab and, on the right side, you have an option called Output Type. You can choose whatever you want; for example, if you want your project to emit a DLL, just choose Class Library.

Screenshot for choosing output type for a project

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
  • this still gives me a .dll when using https://marketplace.visualstudio.com/items?itemName=VisualStudioClient.MicrosoftVisualStudio2017InstallerProjects to create an installer, even if I chose "Windows Application" as my Output Type – paraJdox1 Aug 05 '21 at 08:10
1

When you are setting up the Application Folder: Add/Project Output/... on the options to choose, pick "Publish items" instead of "Primary Output". This will package .exe files instead of .dll, if you do want .dll files, then choose "Primary Output" to the Output Group.