[dotnet] Pack `net462` target framework by nvborisenko ยท Pull Request #16564 ยท SeleniumHQ/selenium

User description

๐Ÿ”— Related Issues

Fixes #16539
Related to #14600

๐Ÿ’ฅ What does this PR do?

Build for net462 framework to avoid binding redirects for System.Text.Json assembly. Selenium assembly now has correct reference to System.Text.Json v8.0.0.5.

๐Ÿ”ง Implementation Notes

Verified locally. Now installing Selenium.WebDriver package doesn't produce unnecessary binding redirection:

      <dependentAssembly>
        <assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-8.0.0.5" newVersion="8.0.0.5" />
      </dependentAssembly>

๐Ÿ’ก Additional Considerations

It is still important to:

      <dependentAssembly>
        <assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>

But here we can do nothing, it is how .NET FX works.

๐Ÿ”„ Types of changes

  • Bug fix (backwards compatible)

PR Type

Bug fix, Enhancement


Description

  • Add net462 target framework support to avoid System.Text.Json binding redirects

  • Implement platform detection for net462 using Environment.OSVersion and Process.uname

  • Update NuGet package to include net462 assemblies with proper dependencies

  • Add framework assembly references for System.IO.Compression and System.Net.Http


Diagram Walkthrough

flowchart LR
  A["net462 Framework"] -->|"Platform Detection"| B["ResourceUtilities.cs"]
  A -->|"SeleniumManager Support"| C["SeleniumManager.cs"]
  A -->|"Build Configuration"| D["BUILD.bazel"]
  A -->|"Project Setup"| E["Selenium.WebDriver.csproj"]
  D -->|"Package Generation"| F["NuGet Package"]
  E -->|"Dependencies"| G["paket.nuget.bzl"]
Loading

File Walkthrough

Relevant files
Enhancement
ResourceUtilities.cs
Add net462 platform detection logic                                           

dotnet/src/webdriver/Internal/ResourceUtilities.cs

  • Add conditional compilation for net462 platform detection using
    Environment.OSVersion and Process.uname
  • Implement Unix platform detection via uname command to distinguish
    between macOS and Linux
  • Keep existing RuntimeInformation-based detection for .NET Core/.NET 5+
    frameworks
  • Add necessary using statements for System and System.Diagnostics
+37/-0   
SeleniumManager.cs
Add SeleniumManager net462 compatibility                                 

dotnet/src/webdriver/SeleniumManager.cs

  • Add conditional compilation blocks for net462, netstandard2.0, and
    net8.0_or_greater
  • Implement net462-specific platform detection defaulting to Windows
  • Replace RuntimeInformation.OSDescription with
    Environment.OSVersion.Platform for compatibility
  • Exclude native DLL search directories logic for net462 framework
+9/-3     
Dependencies
paket.nuget.bzl
Update NuGet package dependencies for net462                         

dotnet/paket.nuget.bzl

  • Update System.Numerics.Vectors from version 4.4.0 to 4.5.0
  • Add System.ValueTuple dependency for net462 in System.Text.Json
    package
  • Update System.Text.Json dependencies to include System.ValueTuple for
    net462 and higher frameworks
+3/-2     
Configuration changes
paket.dependencies
Add net462 to paket framework targets                                       

dotnet/paket.dependencies

  • Add net462 to the framework list in paket configuration
  • Update framework targets from net8.0,netstandard2.0 to
    net462,net8.0,netstandard2.0
+1/-1     
Selenium.WebDriver.csproj
Update project file for net462 support                                     

dotnet/src/webdriver/Selenium.WebDriver.csproj

  • Add net462 to TargetFrameworks property
  • Update System.Text.Json PackageReference condition to include net462
  • Add explicit framework assembly references for System.IO.Compression
    and System.Net.Http
+8/-3     
Selenium.WebDriver.nuspec
Add net462 package metadata and files                                       

dotnet/src/webdriver/Selenium.WebDriver.nuspec

  • Add net462 dependency group with System.Text.Json version 8.0.5
  • Add framework assembly declarations for System.IO.Compression and
    System.Net.Http
  • Include file mappings for net462 WebDriver.dll, pdb, and xml
    documentation
+9/-0     
Selenium.WebDriver.StrongNamed.nuspec
Add net462 strong-named package metadata                                 

dotnet/src/webdriver/Selenium.WebDriver.StrongNamed.nuspec

  • Add net462 dependency group with System.Text.Json version 8.0.5
  • Add framework assembly declarations for System.IO.Compression and
    System.Net.Http
  • Include file mappings for net462 WebDriver.StrongNamed assemblies with
    documentation
+9/-0     
Build configuration
BUILD.bazel
Add Bazel build targets for net462                                             

dotnet/src/webdriver/BUILD.bazel

  • Add new webdriver-net462 csharp_library target with net462 framework
  • Add new webdriver-net462-strongnamed csharp_library target for
    strong-named assembly
  • Include both targets in nuget_pack definitions for regular and
    strong-named packages
  • Add required NuGet dependencies for net462 builds
+75/-0