P tray
P tray

Reputation: 83

Visual Studio 2019 Exports C# Program as DLL instead of EXE?

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?

Upvotes: 1

Views: 14400

Answers (4)

BurnsBA
BurnsBA

Reputation: 4939

Even though the "Target OS version" had a value selected, the csproj file was using a target framework of net8.0-windows (this was also the output build folder).

Screenshot for choosing os version

I had to do two things: 1) edit csproj and change outputtype to exe. 2) Changing the "Target OS version" in the dropdown and then back to 7.0 made the .csproj line now read

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0-windows7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>True</UseWPF>
    <PlatformTarget>x64</PlatformTarget>
  </PropertyGroup>
...

Building the app now outputs to \bin\Debug\net8.0-windows7.0, and it generates an .exe.

Upvotes: 0

Eddie de Meira
Eddie de Meira

Reputation: 41

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.

Upvotes: 3

Arun Karunanidhi
Arun Karunanidhi

Reputation: 7

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

Upvotes: -1

Sadra M.
Sadra M.

Reputation: 1542

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.

Upvotes: 2

Related Questions