I have a .NET Core Console application. My goal here is to be able to conditionally DLLImport
a function and call it, but only on Windows runtimes.
I thought maybe if I could access the runtime identifier in the csproj
file, I could conditionally define a constant for that runtime, then in my c# I could surround the DLLImport and calls in #if
/#endif
blocks.
Is it possible to set compilation constants within a csproj
based on the runtime the project is being built for? This is specifically for an SDK-style Project format (that starts with <Project Sdk="Microsoft.NET.Sdk">
) that is targeting .NET Core.
Note: this question gets close, but is for project.json
style projects.
Alternately, is there a better approach to accomplish my goal?