Skip to content

Commit a59d582

Browse files
CopilotLoopedBard3
andcommitted
Improve version comparison logic for MAUI SDK installation
Co-authored-by: LoopedBard3 <[email protected]>
1 parent 4172644 commit a59d582

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/scenarios/shared/mauisharedpython.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,20 @@ def install_latest_maui(
234234
getLogger().warning(f"Failed to read SDK version from global.json: {e}")
235235

236236
# Compare versions to see if the MAUI SDK version is earlier
237-
if current_sdk_version and maui_sdk_version < current_sdk_version:
237+
# We need to be careful with version comparison, especially with preview versions
238+
is_earlier_version = False
239+
try:
240+
# First, try to parse the versions using packaging.version for proper semantic version comparison
241+
from packaging import version
242+
maui_ver = version.parse(maui_sdk_version)
243+
current_ver = version.parse(current_sdk_version)
244+
is_earlier_version = maui_ver < current_ver
245+
except (ImportError, Exception) as e:
246+
# Fallback to simple string comparison if packaging module is not available
247+
getLogger().warning(f"Using simple string comparison for versions due to: {e}")
248+
is_earlier_version = maui_sdk_version < current_sdk_version
249+
250+
if current_sdk_version and is_earlier_version:
238251
getLogger().info(f"MAUI SDK version {maui_sdk_version} is earlier than global.json version {current_sdk_version}. Temporarily moving global.json.")
239252
if os.path.exists(global_json_path):
240253
try:

0 commit comments

Comments
 (0)