#pragma warning restore CS3021
        #endregion

        private static IEnumerable <VisualStudioInstallation> QueryVsWhere()
        {
            var progpath = FileUtility
                           .FindPackageAssetFullPath("VSWhere a:packages", "vswhere.exe")
                           .FirstOrDefault();

            if (string.IsNullOrWhiteSpace(progpath))
            {
                return(Enumerable.Empty <VisualStudioInstallation>());
            }

            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = progpath,
                    Arguments              = "-prerelease -format json -utf8",
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                }
            };

            using (process)
            {
                var json = string.Empty;

                process.OutputDataReceived += (o, e) => json += e.Data;
                process.Start();
                process.BeginOutputReadLine();
                process.WaitForExit();

                var result = VsWhereResult.FromJson(json);
                return(result.ToVisualStudioInstallations());
            }
        }
Пример #2
0
        private bool OpenWindowsApp(string path, int line)
        {
            var progpath = FileUtility
                           .FindPackageAssetFullPath("COMIntegration a:packages", "COMIntegration.exe")
                           .FirstOrDefault();

            if (string.IsNullOrWhiteSpace(progpath))
            {
                return(false);
            }

            string absolutePath = "";

            if (!string.IsNullOrWhiteSpace(path))
            {
                absolutePath = Path.GetFullPath(path);
            }

            // We remove all invalid chars from the solution filename, but we cannot prevent the user from using a specific path for the Unity project
            // So process the fullpath to make it compatible with VS
            var solution = GetOrGenerateSolutionFile(path);

            if (!string.IsNullOrWhiteSpace(solution))
            {
                solution = $"\"{solution}\"";
                solution = solution.Replace("^", "^^");
            }

            var process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = progpath,
                    Arguments              = $"\"{CodeEditor.CurrentEditorInstallation}\" \"{absolutePath}\" {solution} {line}",
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                }
            };
            var result = process.Start();

            while (!process.StandardOutput.EndOfStream)
            {
                var outputLine = process.StandardOutput.ReadLine();
                if (outputLine == "displayProgressBar")
                {
                    EditorUtility.DisplayProgressBar("Opening Visual Studio", "Starting up Visual Studio, this might take some time.", .5f);
                }

                if (outputLine == "clearprogressbar")
                {
                    EditorUtility.ClearProgressBar();
                }
            }

            var errorOutput = process.StandardError.ReadToEnd();

            if (!string.IsNullOrEmpty(errorOutput))
            {
                Console.WriteLine("Error: \n" + errorOutput);
            }

            process.WaitForExit();
            return(result);
        }
Пример #3
0
 public static void FindVSWhere()
 {
     _vsWherePath = FileUtility
                    .FindPackageAssetFullPath("VSWhere a:packages", "vswhere.exe")
                    .FirstOrDefault();
 }