0

We've got a handful of different custom build configurations in our solution for dev, test, staging, training, prod, etc. These different configurations are, for the most part, used to transform web.config files upon deployment.

I was wondering, however, if there's any way to tell from within your code what configuration was used for the build?

DMac the Destroyer
  • 5,240
  • 6
  • 36
  • 56

2 Answers2

1

You could to use preprocessor directives:

#if DEBUG
string disclaimer = "Debug mode";
#elif RELEASE
string disclaimer = "Release mode";
#endif

Console.WriteLine(disclaimer);
Rubens Farias
  • 57,174
  • 8
  • 131
  • 162
0

The short answer was no, but what I wanted to do was a code smell anyway.

We ended up adding values to the Configuration Manager (Web.config, in our case) and used web.config transforms to modify the values depending on the build configuration. Our scenario didn't seem like a valid use case for preprocessor directives, and my current understanding is that most use cases aren't suitable for preprocessor directives.

Community
  • 1
  • 1
DMac the Destroyer
  • 5,240
  • 6
  • 36
  • 56