3

I have multi ConfigurationName: Release-2018, Release-2019, Release-2020, Debug-2018, Debug-2019, Debug-2020

How can I check if "$(ConfigurationName)" contains "Release"?

I have tried:

if "$(ConfigurationName)".Contains("Release") ....<do something>

Currently I used:

if "$(ConfigurationName)" == "Release-2018" ....<do something>

if "$(ConfigurationName)" == "Release-2019" ....<do something>

if "$(ConfigurationName)" == "Release-2020" ....<do something>

but It seems a bad solution.

Is there any function to help me?

Thank you.

Shai Nguyễn
  • 85
  • 1
  • 7

1 Answers1

1

A simple solution is to define Conditional compliation symbols in your Build properties for each Configuration.

enter image description here

Then you can run custom code section based on your symbols by conditional if-else directives.

#if YOURCFG1
Console.WriteLine("YourCfg is selected build configuration");
//<do something>
#endif
koviroli
  • 1,422
  • 1
  • 15
  • 27