我尝试在 .Net Core 中使用预处理指令,但是我无法确定正确的方法来设置指令:
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
#if MAC
Console.WriteLine("MAC");
#else
Console.WriteLine("NOT MAC");
#endif
}
我尝试了各种排列组合的命令行,但好像还是缺少了些东西。以下是运行各种构建和运行命令时的Shell输出:
~/dev/Temp/DirectiveTests $ dotnet msbuild /p:MAC=TRUE
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
~/dev/Temp/DirectiveTests $ dotnet run /p:MAC=true
Hello World!
NOT MAC
~/dev/Temp/DirectiveTests $ dotnet run
Hello World!
NOT MAC
根据 dotnet --version
,我正在使用工具版本1.0.1。
有没有人知道如何使用命令行正确设置 .net core 的指令?
DefineConstants
似乎没有起到作用。而且,当我在值中放置多个时,会出现错误 MSB1006,指出该属性无效。 - John Koerner