使用构建配置在 Visual Studio 中创建项目的多个版本 [英] Create multiple versions of a project in Visual Studio using Build Configurations

查看:51
本文介绍了使用构建配置在 Visual Studio 中创建项目的多个版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用配置创建多个版本的项目,就像我们使用 #define#if#endif 一样.

I neeed to create multiple versions of my project using configuration just like we do with #define, #if, #endif.

使用这些预处理器指令的缺点是我需要在项目的几乎每个文件中定义符号,但我想通过我的构建配置来处理这个事情.

The down side of using these preprocessor directives is that I need to define symbols in almost every file of the project but I want to handle this thing by my build configurations.

我什至不确定构建配置是否会帮助我做到这一点.

I am not even sure if Build Configurations will help me to do this.

我想要的是,如果我创建一个名为Development"的配置而另一个名为QA"的配置,我的代码将如下所示:

What I want is if I create a configuration with name "Development" and other with name "QA", my code would look like:

if #Development or if $QA

请指导我实现这一目标.

Kindly guide me towards achieving this.

推荐答案

Configuration Manager 就是因为这个原因而存在的.

Configuration Manager exist for this reason.

  • 转到配置管理器并创建一个新配置从预定义的 DEBUG 配置复制
  • 将配置命名为 DEVELOPMENT 并应用于所有项目
  • 选择 DEVELOPMENT 配置作为活动配置(应该已经是活跃的)
  • 转到需要 #if DEVELOPMENT 的每个项目的属性页面有条件地编译并在 BUILD 选项卡的第一个文本框中插入 DEVELOPMENT 符号
  • Go to the Configuration Manager and create a New Configuration copying from the predefined DEBUG configuration
  • Name the configuration DEVELOPMENT and apply to all projects
  • Select as Active Configuration the DEVELOPMENT configuration (should already be the active one)
  • Go to the properties page of each project requiring #if DEVELOPMENT conditional compile and insert the DEVELOPMENT symbol in first textbox of the BUILD tab

现在您的每个项目都可以使用 #if DEVELOPMENT 预处理器指令

Now each of your projects can use the #if DEVELOPMENT preprocessor directive

如果你也需要这个 RELEASE 重复上述步骤,但从预定义的 RELEASE 配置中复制并给出不同的名称

If you need this also for RELEASE repeat the above steps but copy from predefined RELEASE configuration and give a different NAME

现在,可以直接通过 Visual Studio 标准工具栏中的解决方案配置组合工具从定义或不定义 DEVELOPMENT 符号的配置切换,而无需编辑每个项目.

Now switching from a configuration with or without the DEVELOPMENT symbol defined could be done directly from the Solution Configurations combo Tool present in the Standard Toolbar of Visual Studio without editing each project.

您还可以查看 MSDN 文章如何:创建和编辑配置

You can also view MSDN article How to: Create and Edit Configurations

这篇关于使用构建配置在 Visual Studio 中创建项目的多个版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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