C#: A hyphen in a preprocessor directive

Viewed 436

I am reading the machine name from an environment variable COMPUTERNAME into a conditional compilation symbol:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <DefineConstants>TRACE;$(COMPUTERNAME)</DefineConstants>
</PropertyGroup>

After this, I declare a preprocessor directive to compile some code depending on the machine name:

#if MY-MACHINE
// Some code
#elif SOME-ELSE-MACHINE
// Other lines of code...
#else
// ...
#endif

However, the machine name can have a hyphen (-) in it, so I'm getting errors and I cannot build the project with this configuration. When typing the code above in Visual Studio, I get the error:

Error CS1025 Single-line comment or end-of-line expected

and when building even without the conditional compilation statement, I get a warning:

Warning MSB3052 The parameter to the compiler is invalid, '/define:MY-MACHINE' will be ignored.

How to get around this? Is there some way to "escape" the conditional compilation symbols. Or should I just give up with this and read the environment variable runtime?

0 Answers
Related