No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VisualStudioInstallation.cs 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.IO;
  7. using Unity.CodeEditor;
  8. using IOPath = System.IO.Path;
  9. namespace Microsoft.Unity.VisualStudio.Editor
  10. {
  11. internal interface IVisualStudioInstallation
  12. {
  13. string Path { get; }
  14. bool SupportsAnalyzers { get; }
  15. Version LatestLanguageVersionSupported { get; }
  16. string[] GetAnalyzers();
  17. CodeEditor.Installation ToCodeEditorInstallation();
  18. bool Open(string path, int line, int column, string solutionPath);
  19. IGenerator ProjectGenerator { get; }
  20. void CreateExtraFiles(string projectDirectory);
  21. }
  22. internal abstract class VisualStudioInstallation : IVisualStudioInstallation
  23. {
  24. public string Name { get; set; }
  25. public string Path { get; set; }
  26. public Version Version { get; set; }
  27. public bool IsPrerelease { get; set; }
  28. public abstract bool SupportsAnalyzers { get; }
  29. public abstract Version LatestLanguageVersionSupported { get; }
  30. public abstract string[] GetAnalyzers();
  31. public abstract IGenerator ProjectGenerator { get; }
  32. public abstract void CreateExtraFiles(string projectDirectory);
  33. public abstract bool Open(string path, int line, int column, string solutionPath);
  34. protected Version GetLatestLanguageVersionSupported(VersionPair[] versions)
  35. {
  36. if (versions != null)
  37. {
  38. foreach (var entry in versions)
  39. {
  40. if (Version >= entry.IdeVersion)
  41. return entry.LanguageVersion;
  42. }
  43. }
  44. // default to 7.0
  45. return new Version(7, 0);
  46. }
  47. protected static string[] GetAnalyzers(string path)
  48. {
  49. var analyzersDirectory = IOPath.GetFullPath(IOPath.Combine(path, "Analyzers"));
  50. if (Directory.Exists(analyzersDirectory))
  51. return Directory.GetFiles(analyzersDirectory, "*Analyzers.dll", SearchOption.AllDirectories);
  52. return Array.Empty<string>();
  53. }
  54. public CodeEditor.Installation ToCodeEditorInstallation()
  55. {
  56. return new CodeEditor.Installation() { Name = Name, Path = Path };
  57. }
  58. }
  59. }