in src/Microsoft.VisualStudio.SlnGen/VisualStudioLauncher.cs [29:110]
public static bool TryLaunch(ProgramArguments arguments, VisualStudioInstance visualStudioInstance, string solutionFileFullPath, ISlnGenLogger logger)
{
if (!arguments.ShouldLaunchVisualStudio())
{
return true;
}
if (!Utility.RunningOnWindows)
{
logger.LogWarning("Launching Visual Studio is not currently supported on your operating system.");
return true;
}
string devEnvFullPath = arguments.GetDevEnvFullPath(visualStudioInstance);
if (!devEnvFullPath.IsNullOrWhiteSpace())
{
visualStudioInstance = VisualStudioConfiguration.GetInstanceForPath(devEnvFullPath);
}
if (visualStudioInstance == null)
{
logger.LogError(
Program.CurrentDevelopmentEnvironment.IsCorext
? $"Could not find a Visual Studio {Environment.GetEnvironmentVariable("VisualStudioVersion")} installation. Please do one of the following:\n a) Specify a full path to devenv.exe via the -vs command-line argument\n b) Update your corext.config to specify a version of MSBuild.Corext that matches a Visual Studio version you have installed\n c) Install a version of Visual Studio that matches the version of MSBuild.Corext in your corext.config"
: "Could not find a Visual Studio installation. Please run from a command window that has MSBuild.exe on the PATH or specify the full path to devenv.exe via the -vs command-line argument");
return false;
}
if (visualStudioInstance.IsBuildTools)
{
logger.LogError("Cannot use a BuildTools instance of Visual Studio.");
return false;
}
if (!File.Exists(devEnvFullPath))
{
logger.LogError($"The specified path to Visual Studio ({devEnvFullPath}) does not exist or is inaccessible.");
return false;
}
CommandLineBuilder commandLineBuilder = new CommandLineBuilder();
commandLineBuilder.AppendFileNameIfNotNull(solutionFileFullPath);
if (!arguments.ShouldLoadProjectsInVisualStudio())
{
commandLineBuilder.AppendSwitch(DoNotLoadProjectsCommandLineArgument);
}
try
{
Process process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = devEnvFullPath,
Arguments = commandLineBuilder.ToString(),
UseShellExecute = false,
},
};
logger.LogMessageHigh("Launching Visual Studio...");
logger.LogMessageLow(" FileName = {0}", process.StartInfo.FileName);
logger.LogMessageLow(" Arguments = {0}", process.StartInfo.Arguments);
if (!process.Start())
{
logger.LogError("Failed to launch Visual Studio.");
}
}
catch (Exception e)
{
logger.LogError($"Failed to launch Visual Studio. {e.Message}");
}
return true;
}