-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add intrinsic property function IsOSPlatform(string os)
#568
Conversation
050ba6b
to
aa280a7
Compare
Usage: $([MSBuild]::IsOSPlatform(Windows)) Based on @dsplaisted's suggestion in issue dotnet#539 .
aa280a7
to
661a0f6
Compare
case "windows": return NativeMethodsShared.IsWindows; | ||
case "osx": return NativeMethodsShared.IsOSX; | ||
case "unix": return NativeMethodsShared.IsUnixLike; | ||
default: return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense for full-framework and Mono builds, since the CoreFX method doesn't exist there. When it does, though, should this be a passthrough to RuntimeInformation.IsOSPlatform(OSPlatform.Create(os))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but then we need to ensure that they support the same "set".
Looking at this and this, the name depends on PAL_UNIX_NAME
set in the configure.cmake
using CMAKE_SYSTEM_NAME
.
This and this suggest that it uses uname -s
, when available, for this. So, we could use uname -s
too on non-windows systems. Darwin
->OSX
being the special case.
And maybe add a Unix
too (== IsUnixLike
) ?
Since you're adding an intrinsic, could we expand the scope a bit. :-) There are many "Unix" or Unix-like platforms, e.g. Linux, AIX, FreeBSD, OpenBSD, NetBSD, Solaris... -- which all have their distinct features. Additionally, various versions of Windows also have their own "quirks" and features. Aside, consider the uname(1) program, which allows determine the kernel name (e.g. "Darwin", "Linux"), version number, hardware architecture, and more. What might be handy is if the
would return True when running on x86_64 OS X and False elsewhere. |
@jonpryor We discussed this today and while I don't disagree it could be helpful it's something the Framework should provide and we want this to pass through and support only what the Framework returns. In the case of full Framework or Mono where return RuntimeInformation.IsOSPlatform(OSPlatform.Create(os)) Make sense? Do you think there will be cases where extra information would be important to the build? Generally it seems to be test for Windows or not Windows. |
I have my own possible purposes for such a thing. :-) In particular, native libraries. Visual Studio will generate MSBuild-compatible I would like to be able to use This could presumably be handled with Where things get potentially "wonky" is dealing with OS differences. Not all Unixes are alike (nor are all Windows versions...), so I can imagine that being able to query OS name/version/architecture/etc. would allow default-setting properties/items/etc. so that things can more sanely "Just Work" without needing to explicitly specify configurations or override properties. Aside: Where does the Clear as mud? Or a reason to rethink this my fundamental brain damage in the first place? :-) |
...and now that we've open-sourced some things, I can provide pointers. :-) In the absence of a "useful"
This works, but is kinda ugly in that I need to use a filesystem path to distinguish between OS X and Linux ( What do I do with that information? I choose which Android SDK files to install:
I change compiler build options based on the host OS
...and I change I'm sure there will be more. |
We'd like to hold off on this now. Please reopen if you feel strongly. Ideally MSBuild doesn't have a list of known operating systems of flavors of those and passes through to the framework. Since this isn't really possible with Mono (since it doesn't exist in full framework yet), there doesn't seem to be a good alternative. I'm not sure that there's a significant ask for it right now either, and an alternative on .NET Core (the method is in the white-list) already exists. |
Usage:
$([MSBuild]::IsOSPlatform(Windows))
Based on @dsplaisted's suggestion in issue #539 .