I use a global solution NuGet package that has issues with Windows 7 in the latest version. I now want to chose the older version of the NuGet package on Windows 7 until the issue gets fixed, but use the newer and much faster version on Windows 10.
I add the NuGet package reference in my Directory.Build.props but I can't find a way to add a property or condition to find the Windows version.
I tried using a parameter like
<OsVersion>
$(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion@CurrentVersion)
</OsVersion>
but I can't read the registry from dotnet 3.1 build command. I tried [MSBuild]::GetRegistryValue and [MSBuild]::GetRegistryValueFromView, but neither seems to work.
I found this bug in dotnet/sdk github which seems reading registry is not working for dotnet, https://github.com/dotnet/sdk/issues/13958
So how do I get the Windows version so I can use it in the condition? Is there another way?
Thanks
My Directory.Build.Props
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OsVersion>$(registry:HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion@CurrentVersion)</OsVersion>
</PropertyGroup>
<Choose>
<When Condition="$(OsVersion) == '6.1'">
<ItemGroup>
<PackageReference Include="SomeNugetPackage">
<Version>1.7</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<PackageReference Include="SomeNugetPackage">
<Version>1.10</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Otherwise>
</Choose>
</Project>