Search code examples
.net-core.net-5csproj

Change target framework depending on operating system


I'm working on a project with someone else; they are using Linux, and I am using Windows.

Right now, I have this in my .csproj:

<TargetFrameworks>net5.0;net5.0-windows</TargetFrameworks>

but I need a way to say "if we are on Windows, use this target framework; else, use this other one." Is this possible?


Solution

  • You can apply a preprocessor. Take a look at this topic. That should help How to use custom preprocessor directives in .Net Core