I am trying to use a preprocessor directive in .NET Core, but I can't determine the correct way to get the directive to be set:
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
#if MAC
Console.WriteLine("MAC");
#else
Console.WriteLine("NOT MAC");
#endif
}
I have tried various permutations from the command line to get this to work, but I seem to be missing something. Here is the shell output when I run various build and run commands:
cd ~/dev/Temp/DirectiveTests
dotnet msbuild /p:MAC=TRUE
Output:
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.
DirectiveTests -> /Users/me/dev/Temp/DirectiveTests/bin/Debug/netcoreapp1.1/DirectiveTests.dll
dotnet run /p:MAC=true
Output:
Hello World!
NOT MAC
dotnet run
Output:
Hello World!
NOT MAC
I am using the tooling version 1.0.1 according to dotnet --version.
How can I properly set the directives from the command line using .NET Core?