Expose OperatingSystem APIs as intrinsic property functions #5982
Comments
|
Hi, Thanks. |
|
@vijaya-lakshmi-venkatraman sure, I assigned the issue to you so you can give it a try :) I think adding an entry similar to msbuild/src/Build/Resources/Constants.cs Line 379 in 5b9216a You'll probably need to wrap it in some ifdef, e.g. msbuild/src/Directory.BeforeCommon.targets Line 127 in 5b9216a Also tests would be good :) |
|
Thank you for assigning the issue. Please can you explain a bit on the change related to adding an entry similar to RuntimeInformation. |
|
It would look something like this: var fileType = new Tuple<string, Type>(null, typeof(File));
var runtimeInformationType = new Tuple<string, Type>(null, typeof(RuntimeInformation));
var osPlatformType = new Tuple<string, Type>(null, typeof(OSPlatform));
+#if FEATURE_OS_APIS
+ var operatingSystemType = new Tuple<string, Type>(null, typeof(OperatingSystem));
+#endif
// Make specific static methods available (Assembly qualified type names are *NOT* supported, only null which means mscorlib):
availableStaticMethods.TryAdd("System.Environment::ExpandEnvironmentVariables", environmentType);
@@ -378,6 +381,9 @@ private static void InitializeAvailableMethods()
availableStaticMethods.TryAdd("Microsoft.Build.Utilities.ToolLocationHelper", new Tuple<string, Type>("Microsoft.Build.Utilities.ToolLocationHelper, Microsoft.Build.Utilities.Core, Version=" + MSBuildConstants.CurrentAssemblyVersion + ", Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", null));
availableStaticMethods.TryAdd("System.Runtime.InteropServices.RuntimeInformation", runtimeInformationType);
availableStaticMethods.TryAdd("System.Runtime.InteropServices.OSPlatform", osPlatformType);
+#if FEATURE_OS_APIS
+ availableStaticMethods.TryAdd("System.OperatingSystem", operatingSystemType);
+#endif
s_availableStaticMethods = availableStaticMethods;
} |
These are new in .NET 5.0: https://docs.microsoft.com/en-us/dotnet/api/system.operatingsystem?view=net-5.0
They expose methods for all the common operating systems like
OperatingSystem.IsWindows()but also still support the API where you pass in a string:OperatingSystem.IsOSPlatform(string platform).The new APIs are easier to understand so we should consider exposing them.
The text was updated successfully, but these errors were encountered: