How do I check the active solution configuration V

2019-01-27 14:30发布

I would like to enable/disable some code based on a custom solution configuration I added in Visual Studio. How do I check this value at runtime?

4条回答
Bombasti
2楼-- · 2019-01-27 14:50

In each project's properties under the build section you can set different custom constants for each solution configuration. This is where you define custom pre-compiler directives.

查看更多
女痞
3楼-- · 2019-01-27 14:52

You can use precompiler directives within Visual Studio. The #if directive will allow you to determine if you are going to include code or not based on your custom solution configuration.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-27 14:55

add a const value assign to a value that designate the configuration you are in. like

#ifdef _ENABLE_CODE1_
const codeconfig = 1;
#else
const codeconfig = 2;
#endif

and add _ENABLE_CODE1_ in your configuration preprocessor.

查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-27 14:57

I'm not sure if you can figure out the exact name of the build configuration. Howerver, if you use Debug.Assert(...), that code will only be run when you compile in debug mode. Not sure it that helps you at all.

查看更多
登录 后发表回答