Skip to content
Permalink
Browse files

[Install] Prerequisites: Improve Visual Studio detection/update mecha…

…nism
  • Loading branch information
xen2 committed Jan 24, 2019
1 parent fe85d99 commit e435015424568631aabcfbdc9fe409554b1b0fec
@@ -87,14 +87,19 @@ public static class VisualStudioVersions
{
// ReSharper disable once InconsistentNaming
private const int REGDB_E_CLASSNOTREG = unchecked((int)0x80040154);
private static readonly Lazy<List<IDEInfo>> IDEInfos = new Lazy<List<IDEInfo>>(BuildIDEInfos);
private static Lazy<List<IDEInfo>> IDEInfos = new Lazy<List<IDEInfo>>(BuildIDEInfos);

public static IDEInfo DefaultIDE = new IDEInfo("0.0", "Default IDE", string.Empty);

public static IEnumerable<IDEInfo> AvailableVisualStudioInstances => IDEInfos.Value.Where(x => x.HasDevenv);

public static IEnumerable<IDEInfo> AvailableBuildTools => IDEInfos.Value.Where(x => x.HasBuildTools);

public static void Refresh()
{
IDEInfos = new Lazy<List<IDEInfo>>(BuildIDEInfos);
}

private static List<IDEInfo> BuildIDEInfos()
{
var ideInfos = new List<IDEInfo>();
@@ -112,9 +112,44 @@ private static void CheckVisualStudioAndBuildTools()
var vsInstallerPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Microsoft Visual Studio\Installer\vs_installer.exe");
if (AllowVisualStudioOnly && existingVisualStudio2017Install != null && File.Exists(vsInstallerPath))
{
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"modify --passive --norestart --installPath \"{existingVisualStudio2017Install.InstallationPath}\" {string.Join(" ", NecessaryVS2017Workloads.Select(x => $"--add {x}"))}");
if (vsInstallerExitCode == 0)
MessageBox.Show("Visual Studio 2017 was missing the .NET desktop develpment workload.\r\nWe highly recommend a reboot after the installation is finished, otherwise Xenko projects won't compile.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
// First, check if a Visual Studio update is needed
// VS2017: 15.8+ (for .NET Core 2.1)
if (existingVisualStudio2017Install.Version.Major == 15 && existingVisualStudio2017Install.Version.Minor < 8)
{
// Not sure why, but it seems VS Update is sometimes sending Ctrl+C to our process...
try
{
Console.CancelKeyPress += Console_IgnoreControlC;
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"update --passive --norestart --installPath \"{existingVisualStudio2017Install.InstallationPath}\"");
if (vsInstallerExitCode != 0)
{
var errorMessage = $"Visual Studio 2017 update failed with error {vsInstallerExitCode}";
MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new InvalidOperationException(errorMessage);
}
}
finally
{
Console.CancelKeyPress -= Console_IgnoreControlC;
}
}

// Check workloads
{
var vsInstallerExitCode = RunProgramAndAskUntilSuccess("Visual Studio", vsInstallerPath, $"modify --passive --norestart --installPath \"{existingVisualStudio2017Install.InstallationPath}\" {string.Join(" ", NecessaryVS2017Workloads.Select(x => $"--add {x}"))}");
if (vsInstallerExitCode != 0)
{
var errorMessage = $"Visual Studio 2017 install failed with error {vsInstallerExitCode}";
MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
throw new InvalidOperationException(errorMessage);
}
}

// Refresh existingVisualStudio2017Install.Complete and check if restart is needed
VisualStudioVersions.Refresh();
existingVisualStudio2017Install = VisualStudioVersions.AvailableVisualStudioInstances.FirstOrDefault(x => x.InstallationPath == existingVisualStudio2017Install.InstallationPath);
if (existingVisualStudio2017Install != null && !existingVisualStudio2017Install.Complete)
MessageBox.Show("Visual Studio 2017 install needs a computer restart.\r\nIf you don't restart, Xenko projects likely won't compile.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
@@ -145,5 +180,11 @@ private static void CheckVisualStudioAndBuildTools()
}
}
}

private static void Console_IgnoreControlC(object sender, ConsoleCancelEventArgs e)
{
if (e.SpecialKey == ConsoleSpecialKey.ControlC && !e.Cancel)
e.Cancel = true;
}
}
}

0 comments on commit e435015

Please sign in to comment.
You can’t perform that action at this time.