Tuesday, April 10, 2012

How to modify/create build configurations in Visual Studio?



In project life cycle you might need to create or access various builds like Development, Testing, User Acceptance Testing, Production etc. Visual Studio provides Configuration Manager Toolbar to change, create or access builds. By default solution has two builds Debug and Release.

Typically debug build is used to debug and detect errors (compile-time and runtime) from solution or project. Once project or solution development is complete and ready to deploy than project or solution should be built in Release mode. Release builds enables code optimization and enables fast execution of program.

You can also change or create new configuration using configuration dropdown available on standard toolbar.


For add or change configuration you can select configuration manager from any of the drop down. If sometimes configuration or platform drop downs are not visible on standard tool bar of visual studio in such case you can add those externally by clicking on customize menu item of tools menu.


The Configuration Manager Dialog will appear.


Similarly you can open Configuration Manager Dialog from right click of your solution and click on Configuration Manager (below image).

You can change or edit configuration and platform for each project under solution.


The same configuration used to develop application to choose correct config file or connection string or other configuration specific task. Let’s have a look on below code.

#if DEV
        Console.WriteLine("DEV Configuration...");
#elif QA
        Console.WriteLine("QA Configuration...");
#endif

As per above code, based on selected configuration either DEV or QA the appropriate code will execute. One more thing, by default Debug and Release configuration added with project and during compilation it will create Debug and Release folder under Bin folder located at solution folder. If we added new configurations in our case DEV and QA then respective folder will get created under solution’s Bin folder and respective resource and assembly will be added to that.



No comments:

Post a Comment