|
1 | 1 | // Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
|
2 | 2 | // Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
|
3 |
| -using System; |
4 | 3 | using System.Diagnostics;
|
5 |
| -using System.IO; |
6 |
| -using System.Linq; |
7 |
| -using Stride.Core.CodeEditor.VisualStudio; |
| 4 | +using Stride.Core.CodeEditorSupport.VisualStudio; |
8 | 5 |
|
9 |
| -namespace Stride.VisualStudio.PackageInstall |
| 6 | +namespace Stride.VisualStudio.PackageInstall; |
| 7 | + |
| 8 | +static class Program |
10 | 9 | {
|
11 |
| - class Program |
| 10 | + static int Main(string[] args) |
12 | 11 | {
|
13 |
| - static int Main(string[] args) |
| 12 | + try |
14 | 13 | {
|
15 |
| - try |
| 14 | + if (args.Length == 0) |
16 | 15 | {
|
17 |
| - if (args.Length == 0) |
18 |
| - { |
19 |
| - throw new Exception("Expecting a parameter such as /install, /repair or /uninstall"); |
20 |
| - } |
| 16 | + throw new Exception("Expecting a parameter such as /install, /repair or /uninstall"); |
| 17 | + } |
| 18 | + |
| 19 | + const string vsixFile = "Stride.vsix"; |
21 | 20 |
|
22 |
| - const string vsixFile = "Stride.vsix"; |
| 21 | + // Locate a VS installation with VSIXInstaller.exe. |
| 22 | + // Select the latest version of VS possible, in case there is some bugfixes or incompatible changes. |
| 23 | + var visualStudioVersionByVsixVersion = VisualStudioVersions.AvailableInstances.Where(x => x.HasVsixInstaller); |
| 24 | + var ideInfo = visualStudioVersionByVsixVersion.OrderByDescending(x => x.InstallationVersion).FirstOrDefault(x => File.Exists(x.VsixInstallerPath)); |
| 25 | + if (ideInfo == null) |
| 26 | + { |
| 27 | + throw new InvalidOperationException($"Could not find a proper installation of Visual Studio 2019 or later"); |
| 28 | + } |
23 | 29 |
|
24 |
| - // Locate a VS installation with VSIXInstaller.exe. |
25 |
| - // Select the latest version of VS possible, in case there is some bugfixes or incompatible changes. |
26 |
| - var visualStudioVersionByVsixVersion = VisualStudioVersions.AvailableInstances.Where(x => x.HasVsixInstaller); |
27 |
| - var ideInfo = visualStudioVersionByVsixVersion.OrderByDescending(x => x.InstallationVersion).FirstOrDefault(x => File.Exists(x.VsixInstallerPath)); |
28 |
| - if (ideInfo == null) |
| 30 | + switch (args[0]) |
| 31 | + { |
| 32 | + case "/install": |
| 33 | + case "/repair": |
29 | 34 | {
|
30 |
| - throw new InvalidOperationException($"Could not find a proper installation of Visual Studio 2019 or later"); |
| 35 | + // Install VSIX |
| 36 | + var exitCode = RunVsixInstaller(ideInfo.VsixInstallerPath, "\"" + vsixFile + "\""); |
| 37 | + if (exitCode != 0) |
| 38 | + throw new InvalidOperationException($"VSIX Installer didn't run properly: exit code {exitCode}"); |
| 39 | + break; |
31 | 40 | }
|
32 | 41 |
|
33 |
| - switch (args[0]) |
| 42 | + case "/uninstall": |
34 | 43 | {
|
35 |
| - case "/install": |
36 |
| - case "/repair": |
37 |
| - { |
38 |
| - // Install VSIX |
39 |
| - var exitCode = RunVsixInstaller(ideInfo.VsixInstallerPath, "\"" + vsixFile + "\""); |
40 |
| - if (exitCode != 0) |
41 |
| - throw new InvalidOperationException($"VSIX Installer didn't run properly: exit code {exitCode}"); |
42 |
| - break; |
43 |
| - } |
44 |
| - |
45 |
| - case "/uninstall": |
46 |
| - { |
47 |
| - // Note: we allow uninstall to fail (i.e. VSIX was not installed for that specific Visual Studio version) |
48 |
| - RunVsixInstaller(ideInfo.VsixInstallerPath, "/uninstall:Stride.VisualStudio.Package.2022 /quiet"); |
49 |
| - break; |
50 |
| - } |
| 44 | + // Note: we allow uninstall to fail (i.e. VSIX was not installed for that specific Visual Studio version) |
| 45 | + RunVsixInstaller(ideInfo.VsixInstallerPath, "/uninstall:Stride.VisualStudio.Package.2022 /quiet"); |
| 46 | + break; |
51 | 47 | }
|
52 |
| - |
53 |
| - return 0; |
54 |
| - } |
55 |
| - catch (Exception e) |
56 |
| - { |
57 |
| - Console.WriteLine($"Error: {e}"); |
58 |
| - return 1; |
59 | 48 | }
|
| 49 | + |
| 50 | + return 0; |
| 51 | + } |
| 52 | + catch (Exception e) |
| 53 | + { |
| 54 | + Console.WriteLine($"Error: {e}"); |
| 55 | + return 1; |
60 | 56 | }
|
| 57 | + } |
61 | 58 |
|
62 |
| - /// <summary> |
63 |
| - /// Starts the VSIX installer at the given path with the given argument, and waits for the process to exit before returning. |
64 |
| - /// </summary> |
65 |
| - /// <param name="pathToVsixInstaller">The path to a VSIX installer provided by a version of Visual Studio.</param> |
66 |
| - /// <param name="arguments">The arguments to pass to the VSIX installer.</param> |
67 |
| - /// <returns><c>True</c> if the VSIX installer exited with code 0, <c>False</c> otherwise.</returns> |
68 |
| - private static int RunVsixInstaller(string pathToVsixInstaller, string arguments) |
| 59 | + /// <summary> |
| 60 | + /// Starts the VSIX installer at the given path with the given argument, and waits for the process to exit before returning. |
| 61 | + /// </summary> |
| 62 | + /// <param name="pathToVsixInstaller">The path to a VSIX installer provided by a version of Visual Studio.</param> |
| 63 | + /// <param name="arguments">The arguments to pass to the VSIX installer.</param> |
| 64 | + /// <returns><c>True</c> if the VSIX installer exited with code 0, <c>False</c> otherwise.</returns> |
| 65 | + private static int RunVsixInstaller(string pathToVsixInstaller, string arguments) |
| 66 | + { |
| 67 | + var process = Process.Start(pathToVsixInstaller, arguments); |
| 68 | + if (process == null) |
69 | 69 | {
|
70 |
| - var process = Process.Start(pathToVsixInstaller, arguments); |
71 |
| - if (process == null) |
72 |
| - { |
73 |
| - return -1; |
74 |
| - } |
75 |
| - process.WaitForExit(); |
76 |
| - return process.ExitCode; |
| 70 | + return -1; |
77 | 71 | }
|
| 72 | + process.WaitForExit(); |
| 73 | + return process.ExitCode; |
78 | 74 | }
|
79 | 75 | }
|
0 commit comments