There is a property that I'd like to give an initial value based on the operating system I'm currently running on: windows, OSX, Linux, etc ... What I'd essentially like to write is the following:
<RoslynRuntimeIdentifier Condition="'$(RoslynRuntimeIdentifier)' == '' AND '$(OS)' == 'Windows_NT'">win7-x64</RoslynRuntimeIdentifier>
<RoslynRuntimeIdentifier Condition="'$(RoslynRuntimeIdentifier)' == '' AND '$(OS)' == 'OSX'"> osx.10.12-x64</RoslynRuntimeIdentifier>
<RoslynRuntimeIdentifier Condition="'$(RoslynRuntimeIdentifier)' == ''>linux-rid</RoslynRuntimeIdentifier>
The $(OS) flag works for windows by producing Windows_NT. I can't find any documentation for this property though and hence can't determine what the values would be for other operating systems. Is this property the write way to approach this and if so what are the values for other operating systems.
If you can commit to 15.3+, you're looking for the property function $([MSBuild]::IsOsPlatform()).
$(OS) is either Windows_NT or Unix, so you have to use trickery to distinguish between macOS and Linux if you go that route.
$(OS) is either Windows_NT or Unix, so you have to use trickery to distinguish between macOS and Linux if you go that route.
What kind of trickery? I'm not afraid of using it but don't know what it is ;)
One hack I've used in the past is this:
Condition=" '$(OS)' == 'Unix' and $([System.IO.File]::Exists('/usr/lib/libc.dylib')) ">...</Condition>
Thank you for posting this "workaround" @akoeplinger
@bgavrilMS I'd recommend using $([MSBuild]::IsOsPlatform()) instead, since it's now been available for many releases and you're unlikely to encounter a 15.0-15.2 MSBuild anywhere.
Docs:
|Function signature|Description|
|------------------------|-----------------|
|bool IsOsPlatform(string platformString)|Specify whether the current OS platform is platformString. platformString must be a member of OSPlatform.|
@rainersigwald
Your solution works for me in macOS with dotnet core 2.1.505
Thanks馃憤
Most helpful comment
@bgavrilMS I'd recommend using
$([MSBuild]::IsOsPlatform())instead, since it's now been available for many releases and you're unlikely to encounter a 15.0-15.2 MSBuild anywhere.Docs:
|Function signature|Description|
|------------------------|-----------------|
|bool IsOsPlatform(string platformString)|Specify whether the current OS platform is
platformString.platformStringmust be a member ofOSPlatform.|