How to create two different executables from one Visual Studio project

23,604

You can build as many assemblies in one solution as you like. Assemblies can result in DLL files or EXE files.

Create a solution (or open an existing solution).

  1. Right-click the root node in Solution Explorer and choose AddNew Project and choose the project type you like to add.

  2. Right-click the project item in Solution Explorer and choose PropertiesBuildOutput path. Set to the desired directory where to build it to. Repeat this for the other projects.

This way you get the following in Solution Explorer:

  • MySolution
    • MyCommonCode (Class Library, results in MyCommonCode.dll)
    • MyMainApp (Windows Forms application, results in MyMainApp.exe)
    • MyConfigApp (Windows Forms application, results in MyConfigApp.exe)

The MyCommonCode assembly contains shared code that both EXE files are using like the identifiers of your configuration file, etc.

MyMainApp is the GUI application (Windows Forms, WPF, etc.) for your main application with a project-reference to the MyComonCode project.

MyConfigApp is a GUI application for editing the configuration values with a project reference to MyCommonCode project.

After building your solution you get the following binaries: MyCommonCode.dll, MyMainApp.exe, and MyConfigApp.exe.

Update based on the comment:

One compile-run can build only one binary (DLL or EXE) per project. You can do something like the answer above: move most of the code in a common/core DLL and make two thin projects for the two EXE files which only "configure and use" the central common/core DLL file.

You can build different EXE files based on the same project using compiler defines. You can even define your own defines. But per compile-run you can only build one binary (DLL, EXE) per project - one or the other, but not both.

Share:
23,604
Gevo12321
Author by

Gevo12321

I wish I was a programmer by trade

Updated on September 14, 2020

Comments

  • Gevo12321
    Gevo12321 over 3 years

    I have a main executable that runs based on settings saved in a configuration file. I want to be able to change the settings in the config file through a different executable.

    Is there an easy way of building these two different executables in one Windows Forms project? Meaning that when I press build, two different EXE files get created in the same solution folder - the one that changes the configuration file, and the other that uses it.

    I know that this is possible to do if I create two separate projects that use the same solution folder, but I was hoping to do it all in one step.

    I am assuming that to do this, I need a project with two "Main" functions. Is this possible?

  • Gevo12321
    Gevo12321 over 8 years
    The reason I want to do this is to have an "admin" who has access to the config editor to be able to control which features a "non-admin" user has access to.
  • PaulG
    PaulG over 8 years
    That's all correct of course, but it's not what he asked. The question title is multiple executables in a project. And he further stated "I know that this is possible to do if I create two separate projects that use the same solution folder"
  • PaulG
    PaulG over 8 years
    Still, I think the short answer to his question is 'no', and would say this is the correct way to tackle the problem. Put the config and code to read/update it into the shared 'Common' project.