Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

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

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Configuration Manager exist for this reason.

  • 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

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

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

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...