Multilspy: fix dotnet version detection

don't just use first line of output, instead use latest available and allowed version
This commit is contained in:
Michael Panchenko committed 2025-06-11 17:08:32 +02:00
1 parent b33af12203
commit 40b9a246f0
1 file changed
+23 -14
+23 -14
View File
@@ -313,23 +313,31 @@ class PlatformUtils:
"""
try:
result = subprocess.run(["dotnet", "--list-runtimes"], capture_output=True, check=True)
version = ''
available_version_cmd_output = []
for line in result.stdout.decode('utf-8').split('\n'):
if line.startswith('Microsoft.NETCore.App'):
version = line.split(' ')[1]
break
if version == '':
version_cmd_output = line.split(' ')[1]
available_version_cmd_output.append(version_cmd_output)
if not available_version_cmd_output:
raise MultilspyException("dotnet not found on the system")
if version.startswith("8"):
return DotnetVersion.V8
elif version.startswith("7"):
return DotnetVersion.V7
elif version.startswith("6"):
return DotnetVersion.V6
elif version.startswith("4"):
return DotnetVersion.V4
else:
raise MultilspyException("Unknown dotnet version: " + version)
# Check for supported versions in order of preference (latest first)
for version_cmd_output in available_version_cmd_output:
if version_cmd_output.startswith("8"):
return DotnetVersion.V8
for version_cmd_output in available_version_cmd_output:
if version_cmd_output.startswith("7"):
return DotnetVersion.V7
for version_cmd_output in available_version_cmd_output:
if version_cmd_output.startswith("6"):
return DotnetVersion.V6
for version_cmd_output in available_version_cmd_output:
if version_cmd_output.startswith("4"):
return DotnetVersion.V4
# If no supported version found, raise exception with all available versions
raise MultilspyException(f"No supported dotnet version found. Available versions: {', '.join(available_version_cmd_output)}. Supported versions: 4, 6, 7, 8")
except (FileNotFoundError, subprocess.CalledProcessError):
try:
result = subprocess.run(["mono", "--version"], capture_output=True, check=True)
@@ -338,6 +346,7 @@ class PlatformUtils:
raise MultilspyException("dotnet or mono not found on the system")
class SymbolUtils:
@staticmethod
def symbol_tree_contains_name(roots: list[UnifiedSymbolInformation], name: str) -> bool: