-
-
Notifications
You must be signed in to change notification settings - Fork 938
/
Program.cs
79 lines (73 loc) · 3.44 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) Xenko contributors (https://xenko.com) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Xenko.Core.VisualStudio;
namespace Xenko.VisualStudio.PackageInstall
{
class Program
{
static int Main(string[] args)
{
try
{
if (args.Length == 0)
{
throw new Exception("Expecting a parameter such as /install, /repair or /uninstall");
}
const string vsixFile = "Xenko.vsix";
// Locate VSIXInstaller.exe
// We now only deal with VS2017+ which has a unified installer. Still getting latest version of VS possible, in case there is some bugfixes or incompatible changes.
var visualStudioVersionByVsixVersion = VisualStudioVersions.AvailableVisualStudioInstances.Where(x => x.HasVsixInstaller && x.VsixInstallerVersion == VSIXInstallerVersion.VS2017AndFutureVersions);
var visualStudioVersion = visualStudioVersionByVsixVersion.OrderByDescending(x => x.Version).FirstOrDefault(x => File.Exists(x.VsixInstallerPath));
if (visualStudioVersion == null)
{
throw new InvalidOperationException($"Could not find a proper installation of Visual Studio 2017 or later");
}
switch (args[0])
{
case "/install":
case "/repair":
{
// Install VSIX
var exitCode = RunVsixInstaller(visualStudioVersion.VsixInstallerPath, "\"" + vsixFile + "\"");
if (exitCode != 0)
throw new InvalidOperationException($"VSIX Installer didn't run properly: exit code {exitCode}");
break;
}
case "/uninstall":
{
// Note: we allow uninstall to fail (i.e. VSIX was not installed for that specific VIsual Studio version)
RunVsixInstaller(visualStudioVersion.VsixInstallerPath, "/uninstall:b0b8feb1-7b83-43fc-9fc0-70065ddb80a1");
break;
}
}
return 0;
}
catch (Exception e)
{
Console.WriteLine($"Error: {e}");
return 1;
}
}
/// <summary>
/// Starts the VSIX installer at the given path with the given argument, and waits for the process to exit before returning.
/// </summary>
/// <param name="pathToVsixInstaller">The path to a VSIX installer provided by a version of Visual Studio.</param>
/// <param name="arguments">The arguments to pass to the VSIX installer.</param>
/// <returns><c>True</c> if the VSIX installer exited with code 0, <c>False</c> otherwise.</returns>
private static int RunVsixInstaller(string pathToVsixInstaller, string arguments)
{
var process = Process.Start(pathToVsixInstaller, arguments);
if (process == null)
{
return -1;
}
process.WaitForExit();
return process.ExitCode;
}
}
}