static VisualStudioEditor()
        {
            if (IsWindows)
            {
                Discovery.FindVSWhere();
            }

            CodeEditor.Register(new VisualStudioEditor());

            _discoverInstallations = AsyncOperation <IVisualStudioInstallation[]> .Run(DiscoverInstallations);
        }
예제 #2
0
        internal static void GenerateSolution()
        {
            if (CodeEditor.CurrentEditor is VisualStudioEditor vse)
            {
                Log($"Using default editor settings for Visual Studio installation");
                GenerateSolutionWith(vse, CodeEditor.CurrentEditorInstallation);
            }
            else
            {
                Log($"Visual Studio is not set as your default editor, looking for installations");
                try
                {
                    var installations = Discovery
                                        .GetVisualStudioInstallations()
                                        .Cast <VisualStudioInstallation>()
                                        .OrderByDescending(vsi => !vsi.IsPrerelease)
                                        .ThenBy(vsi => vsi.Version)
                                        .ToArray();

                    foreach (var vsi in installations)
                    {
                        Log($"Detected {GetInstallationDetails(vsi)}");
                    }

                    var installation = installations
                                       .FirstOrDefault();

                    if (installation != null)
                    {
                        var current = CodeEditor.CurrentEditorInstallation;
                        try
                        {
                            CodeEditor.SetExternalScriptEditor(installation.Path);
                            GenerateSolutionWith(CodeEditor.CurrentEditor as VisualStudioEditor, installation.Path);
                        }
                        finally
                        {
                            CodeEditor.SetExternalScriptEditor(current);
                        }
                    }
                    else
                    {
                        Log($"No Visual Studio installation found!");
                    }
                }
                catch (Exception ex)
                {
                    Log($"Error detecting Visual Studio installations: {ex}");
                }
            }
        }
예제 #3
0
 private static IVisualStudioInstallation[] DiscoverInstallations()
 {
     try
     {
         return(Discovery
                .GetVisualStudioInstallations()
                .ToArray());
     }
     catch (Exception ex)
     {
         UnityEngine.Debug.LogError($"Error detecting Visual Studio installations: {ex}");
         return(Array.Empty <IVisualStudioInstallation>());
     }
 }
예제 #4
0
        static VisualStudioEditor()
        {
            if (!UnityInstallation.IsMainUnityEditorProcess)
            {
                return;
            }

            if (IsWindows)
            {
                Discovery.FindVSWhere();
            }

            CodeEditor.Register(new VisualStudioEditor());

            _discoverInstallations = AsyncOperation <IVisualStudioInstallation[]> .Run(DiscoverInstallations);
        }
예제 #5
0
        internal virtual bool TryGetVisualStudioInstallationForPath(string editorPath, out IVisualStudioInstallation 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));
        }
예제 #6
0
        static VisualStudioEditor()
        {
            try
            {
                _installations = Discovery
                                 .GetVisualStudioInstallations()
                                 .ToArray();
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.LogError($"Error detecting Visual Studio installations: {ex}");
                _installations = Array.Empty <VisualStudioInstallation>();
            }

            CodeEditor.Register(new VisualStudioEditor());
        }
예제 #7
0
        private static void CheckCurrentEditorInstallation()
        {
            var editorPath = CodeEditor.CurrentEditorInstallation;

            try
            {
                if (Discovery.TryDiscoverInstallation(editorPath, out _))
                {
                    return;
                }
            }
            catch (IOException)
            {
            }

            UnityEngine.Debug.LogWarning($"Visual Studio executable {editorPath} is not found. Please change your settings in Edit > Preferences > External Tools.");
        }