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[] ar
If you want custom configuration switches that do not impact other settings ("Configurations" like Debug/Release), you can define any other property and use it in your build.
E.g. for dotnet build /p:IsMac=true
you could add the following to your csproj file (not that run
might not pass the property correctly though IsMac=true dotnet run
will work after a clean):
$(DefineConstants);MAC
If you want to go further and automatically detect if you are building on a mac, you can use msbuild property functions to evaluate which OS you are building on. Not that this currently only works for the .net core variant of msbuild (dotnet msbuild
). See this PR for details on the support.
$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::get_OSX())))
$(DefineConstants);MAC