in resharper/resharper-unity/src/Unity/UnityEditorIntegration/UnityInstallationFinder.cs [265:324]
public static VirtualFileSystemPath GetAppPathByDll(XmlElement documentElement)
{
var referencePathElement = documentElement.ChildElements()
.Where(a => a.Name == "ItemGroup").SelectMany(b => b.ChildElements())
.Where(c => c.Name == "Reference" &&
(c.GetAttribute("Include").Equals("UnityEngine") // we can't use StartsWith here, some "UnityEngine*" libs are in packages
|| c.GetAttribute("Include").Equals("UnityEngine.CoreModule") // Dll project may have this reference instead of UnityEngine.dll
|| c.GetAttribute("Include").Equals("UnityEditor")))
.SelectMany(d => d.ChildElements())
.FirstOrDefault(c => c.Name == "HintPath");
if (referencePathElement == null || string.IsNullOrEmpty(referencePathElement.InnerText))
return null;
var filePath = VirtualFileSystemPath.Parse(referencePathElement.InnerText, InteractionContext.SolutionContext);
if (!filePath.IsAbsolute) // RIDER-21237
return null;
if (filePath.ExistsFile)
{
switch (PlatformUtil.RuntimePlatform)
{
case JetPlatform.Windows:
{
return GoUpForUnityExecutable(filePath,$"{Unity}.exe", path => path.ExistsFile)
?? GoUpForUnityExecutable(filePath,$"{Tuanjie}.exe", path => path.ExistsFile);
}
case JetPlatform.Linux:
{
return GoUpForUnityExecutable(filePath, Unity, path => path.ExistsFile)
?? GoUpForUnityExecutable(filePath, Tuanjie, path => path.ExistsFile);
}
case JetPlatform.MacOsX:
{
var result = GoUpForUnityExecutable(filePath, $"{Unity}.app", path => path.ExistsDirectory)
?? GoUpForUnityExecutable(filePath, $"{Tuanjie}.app", path => path.ExistsDirectory);
// not sure, how this worked before: either older Unity versions or assembly is inside the Unity.app/Contents
if (result == null)
{
var appPath = filePath;
while (!appPath.Name.Equals("Contents"))
{
appPath = appPath.Directory;
if (!appPath.ExistsDirectory || appPath.IsEmpty)
return null;
}
appPath = appPath.Directory;
return appPath;
}
return result;
}
default:
ourLogger.Error("Unknown runtime platform");
break;
}
}
return null;
}