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?
The standard Visual Studio toolbar contains a Start button and a solution configuration drop-down to the right of the Start button. This list allows users to choose the configuration to be started when F5 is pressed, create their own solution configurations, or edit an existing configuration.
The configuration and the platform control where built output files are stored. Normally, when Visual Studio builds your project, the output is placed in a project subfolder named with the active configuration (for example, bin/Debug/x86), but you can change that.
In the ConfigurationManager , right-click a configuration name and click Properties.
In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With