Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting operating system #2468

Closed
jaredpar opened this issue Aug 24, 2017 · 7 comments
Closed

Detecting operating system #2468

jaredpar opened this issue Aug 24, 2017 · 7 comments

Comments

@jaredpar
Copy link
Member

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.

@rainersigwald
Copy link
Member

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.

@jaredpar
Copy link
Member Author

$(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 ;)

@akoeplinger
Copy link
Member

One hack I've used in the past is this:

Condition=" '$(OS)' == 'Unix' and $([System.IO.File]::Exists('/usr/lib/libc.dylib')) ">...</Condition>

@bgavrilMS
Copy link

Thank you for posting this "workaround" @akoeplinger

@rainersigwald
Copy link
Member

@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.

@liuziangexit
Copy link

@rainersigwald
Your solution works for me in macOS with dotnet core 2.1.505
Thanks👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants