public static bool TryDiscoverInstallation(string editorPath, out IVisualStudioInstallation installation) { installation = null; if (string.IsNullOrEmpty(editorPath)) { return(false); } if (!IsCandidateForDiscovery(editorPath)) { return(false); } // On windows we use the executable directly, so we can query extra information var fvi = editorPath; // On Mac we use the .app folder, so we need to access to main assembly if (VisualStudioEditor.IsOSX) { fvi = Path.Combine(editorPath, "Contents/Resources/lib/monodevelop/bin/VisualStudio.exe"); if (!File.Exists(fvi)) { fvi = Path.Combine(editorPath, "Contents/MonoBundle/VisualStudio.exe"); } if (!File.Exists(fvi)) { fvi = Path.Combine(editorPath, "Contents/MonoBundle/VisualStudio.dll"); } } if (!File.Exists(fvi)) { return(false); } // VS preview are not using the isPrerelease flag so far // On Windows FileDescription contains "Preview", but not on Mac var vi = FileVersionInfo.GetVersionInfo(fvi); var version = new Version(vi.ProductVersion); var isPrerelease = vi.IsPreRelease || string.Concat(editorPath, "/" + vi.FileDescription).ToLower().Contains("preview"); installation = new VisualStudioInstallation() { IsPrerelease = isPrerelease, Name = $"{vi.FileDescription}{(isPrerelease && VisualStudioEditor.IsOSX ? " Preview" : string.Empty)} [{version.ToString(3)}]", Path = editorPath, Version = version }; return(true); }
internal bool TryGetVisualStudioInstallationForPath(string editorPath, out VisualStudioInstallation installation) { // lookup for well known installations foreach (var candidate in _installations) { if (!string.Equals(Path.GetFullPath(editorPath), Path.GetFullPath(candidate.Path), StringComparison.OrdinalIgnoreCase)) { continue; } installation = candidate; return(true); } return(Discovery.TryDiscoverInstallation(editorPath, out installation)); }