How to create two different executables from one Visual Studio project

后端 未结 2 1198
南方客
南方客 2021-02-05 17:26

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.

相关标签:
2条回答
  • 2021-02-05 17:35

    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.

    0 讨论(0)
  • 2021-02-05 17:45

    The idea of a configuration file is that you don't need to build multiple executable files. ;-)

    You could use the Configuration Manager, to create a new Solution configuration and change the output directory for that configuration.

    0 讨论(0)
提交回复
热议问题