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

Expose OperatingSystem APIs as intrinsic property functions #5982

Open
akoeplinger opened this issue Dec 21, 2020 · 4 comments
Open

Expose OperatingSystem APIs as intrinsic property functions #5982

akoeplinger opened this issue Dec 21, 2020 · 4 comments
Assignees

Comments

@akoeplinger
Copy link
Member

@akoeplinger akoeplinger commented Dec 21, 2020

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.

@vijaya-lakshmi-venkatraman

Hi,
I would like to take this up if still available.
I am a newbie to MSBuild and appreciate any pointers to fix this issue

Thanks.

@akoeplinger
Copy link
Member Author

@akoeplinger akoeplinger commented Apr 30, 2021

@vijaya-lakshmi-venkatraman sure, I assigned the issue to you so you can give it a try :)

I think adding an entry similar to RuntimeInformation here should be enough:

availableStaticMethods.TryAdd("System.Runtime.InteropServices.RuntimeInformation", runtimeInformationType);

You'll probably need to wrap it in some ifdef, e.g. FEATURE_OS_APIS, since the API is only available from .NET 5+, so add the define here in a new PropertyGroup for net5.0 here:

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1' or '$(TargetFramework)' == 'net5.0'">

Also tests would be good :)

@vijaya-lakshmi-venkatraman

Thank you for assigning the issue.
I will add a new PropertyGroup as below:

 <PropertyGroup Condition="'$(TargetFramework)' == 'net5.0'">
    <DefineConstants>$(DefineConstants);FEATURE_OS_APIS</DefineConstants>
  </PropertyGroup>

Please can you explain a bit on the change related to adding an entry similar to RuntimeInformation.
I am afraid I did not get that part :(

@akoeplinger
Copy link
Member Author

@akoeplinger akoeplinger commented May 7, 2021

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;
                    }

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

Successfully merging a pull request may close this issue.

None yet
3 participants