Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. using System;
  6. using System.Linq;
  7. using Unity.CodeEditor;
  8. namespace Microsoft.Unity.VisualStudio.Editor
  9. {
  10. internal static class Cli
  11. {
  12. internal static void Log(string message)
  13. {
  14. // Use writeline here, instead of UnityEngine.Debug.Log to not include the stacktrace in the editor.log
  15. Console.WriteLine($"[VisualStudio.Editor.{nameof(Cli)}] {message}");
  16. }
  17. internal static string GetInstallationDetails(IVisualStudioInstallation installation)
  18. {
  19. return $"{installation.ToCodeEditorInstallation().Name} Path:{installation.Path}, LanguageVersionSupport:{installation.LatestLanguageVersionSupported} AnalyzersSupport:{installation.SupportsAnalyzers}";
  20. }
  21. internal static void GenerateSolutionWith(VisualStudioEditor vse, string installationPath)
  22. {
  23. if (vse != null && vse.TryGetVisualStudioInstallationForPath(installationPath, lookupDiscoveredInstallations: true, out var vsi))
  24. {
  25. Log($"Using {GetInstallationDetails(vsi)}");
  26. vse.SyncAll();
  27. }
  28. else
  29. {
  30. Log($"No Visual Studio installation found in ${installationPath}!");
  31. }
  32. }
  33. internal static void GenerateSolution()
  34. {
  35. if (CodeEditor.CurrentEditor is VisualStudioEditor vse)
  36. {
  37. Log($"Using default editor settings for Visual Studio installation");
  38. GenerateSolutionWith(vse, CodeEditor.CurrentEditorInstallation);
  39. }
  40. else
  41. {
  42. Log($"Visual Studio is not set as your default editor, looking for installations");
  43. try
  44. {
  45. var installations = Discovery
  46. .GetVisualStudioInstallations()
  47. .Cast<VisualStudioInstallation>()
  48. .OrderByDescending(vsi => !vsi.IsPrerelease)
  49. .ThenBy(vsi => vsi.Version)
  50. .ToArray();
  51. foreach(var vsi in installations)
  52. {
  53. Log($"Detected {GetInstallationDetails(vsi)}");
  54. }
  55. var installation = installations
  56. .FirstOrDefault();
  57. if (installation != null)
  58. {
  59. var current = CodeEditor.CurrentEditorInstallation;
  60. try
  61. {
  62. CodeEditor.SetExternalScriptEditor(installation.Path);
  63. GenerateSolutionWith(CodeEditor.CurrentEditor as VisualStudioEditor, installation.Path);
  64. }
  65. finally
  66. {
  67. CodeEditor.SetExternalScriptEditor(current);
  68. }
  69. } else
  70. {
  71. Log($"No Visual Studio installation found!");
  72. }
  73. }
  74. catch (Exception ex)
  75. {
  76. Log($"Error detecting Visual Studio installations: {ex}");
  77. }
  78. }
  79. }
  80. }
  81. }