Create multiple versions of a project in Visual Studio using Build Configurations

I need to create several versions of my project using the configuration in the same way as we do with #define , #if , #endif .

The downside of using these preprocessor directives is that I need to define characters in almost every project file, but I want to handle this thing with my build configurations.

I'm not even sure that Build Configurations will help me with this.

I want to create a configuration named "Development" and another named "QA", my code will look like this:

 if #Development or if $QA 

Please help me achieve this.

+6
source share
2 answers

For this reason, Configuration Manager exists.

  • Go to Configuration Manager and create a new copy configuration from the predefined DEBUG configuration.
  • Name the configuration DEVELOPMENT and apply to all projects
  • Select the DEVELOPMENT configuration as the active configuration (it should already be active)
  • Go to the properties page of each project that requires #if DEVELOPMENT conditionally compile and insert the DEVELOPMENT symbol in the first text field of the BUILD tab.

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

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

Now, switching from a configuration with or without a specific DEVELOPMENT symbol can be performed directly from the combined Solution Configuration tool presented on the standard Visual Studio toolbar without editing each project.

You can also view the MSDN article How to Create and Modify Configurations

+9
source

In addition to Michael Freudzimโ€™s solution, you can use the conditional attribute for central initialization operations or other void functions:

 [Conditional("DEVELOPMENT")] public static void InitDemo() { Models.LogFile.ErrorLog("This is a Development Version!"); // init settings } 

Found here: http://msdn.microsoft.com/de-de/library/4xssyw96%28v=vs.80%29.aspx

0
source

Source: https://habr.com/ru/post/912835/


All Articles