如何从一个Visual Studio项目创建两个不同的可执行文件 [英] How to create two different executables from one Visual Studio project

查看:343
本文介绍了如何从一个Visual Studio项目创建两个不同的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要的可执行文件,它基于保存在配置文件中的设置运行。我希望能够通过一个不同的可执行文件来更改配置文件中的设置。



是否有一种简单的方法可以在一个Windows Forms项目中构建这两个不同的可执行文件?这意味着当我按build键时,将在同一个解决方案文件夹中创建两个不同的EXE文件-一个更改配置文件,另一个使用它。



I我知道如果我创建两个使用相同解决方案文件夹的单独项目是可能的,但是我希望一步完成所有工作。



我假设为此,我需要一个具有两个主要功能的项目。

解决方案

您可以根据需要在一个解决方案中构建尽可能多的程序集。程序集可能会生成DLL文件或EXE文件。



创建解决方案(或打开现有解决方案)。


  1. 在解决方案资源管理器中右键单击根节点,然后选择 Add →。 新项目,然后选择要添加的项目类型。


  2. 在解决方案资源管理器中右键单击项目,然后选择属性 Build 输出路径。设置到所需的目录中。对于其他项目,请重复此操作。
    $ b


    • MySolution


      • MyCommonCode(类库,结果为MyCommonCode.dll)

      • MyMainApp(Windows窗体应用程序,结果在MyMainApp.exe中)

      • MyConfigApp(Windows Forms应用程序,结果在MyConfigApp.exe中)




    MyCommonCode程序集包含两个EXE文件都在使用的共享代码,例如配置文件的标识符等。



    MyMainApp是主应用程序的GUI应用程序(Windows窗体,WPF等),带有对MyComonCode项目的项目引用。



    MyConfigApp是一个GUI应用程序,用于通过引用MyCommonCode项目的项目来编辑配置值。



    构建解决方案后,您将获得以下二进制文件: MyCommonCode.dll MyMain App.exe MyConfigApp.exe



    更新基于注释:



    每个项目一次编译运行只能生成一个二进制文件(DLL或EXE)。您可以执行类似上面的回答的操作:将大多数代码移到公共/核心DLL中,并为两个EXE文件创建两个瘦项目,这些文件仅配置和使用中央的公共/核心DLL文件。



    您可以使用编译器定义根据同一项目构建不同的EXE文件。您甚至可以定义自己的定义。但是,每次编译运行时,每个项目只能构建一个二进制文件(DLL,EXE)-一个或另一个,但不能两者都构建。


    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?

    解决方案

    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.

    这篇关于如何从一个Visual Studio项目创建两个不同的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆