Skip to content

XcodeVersion not populated when Xcode is discovered via xcode-select #164

@emaf

Description

@emaf

Summary

When XcodeLocator discovers the Xcode path via xcode-select --print-path (discovery path #3), the XcodeVersion and DTXcode properties are never populated and remain at their default values (0.0.0 and "" respectively).

This causes downstream consumers that rely on XcodeVersion to see 0.0 instead of the actual Xcode version (e.g., 26.2).

Root Cause

In XcodeLocator.TryLocatingXcode(), the three discovery paths handle version parsing differently:

  1. Env var (line ~109): calls TryLocatingSpecificXcode -> parses version.plist -> sets XcodeVersion
  2. Settings file (line ~120): calls TryLocatingSpecificXcode -> parses version.plist -> sets XcodeVersion
  3. xcode-select (line ~129): calls TryGetSystemXcode -> only returns a path string, does not call TryLocatingSpecificXcode -> XcodeVersion stays at 0.0.0

TryGetSystemXcode is a static method that runs xcode-select --print-path and returns the path, but it never calls TryLocatingSpecificXcode which is responsible for reading Contents/version.plist and populating XcodeVersion and DTXcode.

Reproduction

  1. Have no settings file (~/Library/Preferences/maui/Settings.plist or ~/Library/Preferences/Xamarin/Settings.plist)
  2. Have MD_APPLE_SDK_ROOT unset
  3. Have a valid Xcode configured via xcode-select -s
  4. Create an XcodeLocator and call TryLocatingXcode(null)
  5. Observe XcodeVersion is 0.0.0 instead of the actual version

Suggested Fix

Route the xcode-select path through TryLocatingSpecificXcode like the other two paths already do. In TryLocatingXcode(), around line 129, change:

csharp // 3. Not optional if (TryGetSystemXcode (log, out location)) {

to:

csharp // 3. Not optional if (TryGetSystemXcode (log, out var systemXcodePath) && TryLocatingSpecificXcode (systemXcodePath, out location)) {

This also validates the Xcode bundle from xcode-select (checking for version.plist and Info.plist), which the current code does not do.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions