Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ba68d16

Browse files
committed
Parse the FXR version to properly select the newest one
1 parent ba0a353 commit ba68d16

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

clr_loader/ffi/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
from pathlib import Path
3-
from typing import Optional
3+
from typing import Optional, Tuple
44

55
import cffi # type: ignore
66

@@ -23,7 +23,7 @@ def load_hostfxr(dotnet_root: Path):
2323
hostfxr_path = dotnet_root / "host" / "fxr"
2424
hostfxr_paths = hostfxr_path.glob(f"?.*/{hostfxr_name}")
2525

26-
for hostfxr_path in reversed(sorted(hostfxr_paths)):
26+
for hostfxr_path in reversed(sorted(hostfxr_paths, key=_path_to_version)):
2727
try:
2828
return ffi.dlopen(str(hostfxr_path))
2929
except Exception:
@@ -61,6 +61,15 @@ def load_netfx():
6161
return ffi.dlopen(str(path))
6262

6363

64+
def _path_to_version(path: Path) -> Tuple[int, int, int]:
65+
name = path.parent.name
66+
try:
67+
res = list(map(int, name.split(".")))
68+
return tuple(res + [0, 0, 0])[:3]
69+
except Exception:
70+
return (0, 0, 0)
71+
72+
6473
def _get_dll_name(name: str) -> str:
6574
if sys.platform == "win32":
6675
return f"{name}.dll"

0 commit comments

Comments
 (0)