/// <summary>
        /// Determines whether the specified version is from a "legacy" .NET CLI.
        /// If true, this .NET CLI supports project.json development; otherwise, it supports .csproj development.
        /// </summary>
        public bool IsLegacy(DotNetVersion dotnetVersion)
        {
            if (dotnetVersion.HasError)
            {
                return(false);
            }

            var version = dotnetVersion.Version;

            if (version.Major < 1)
            {
                return(true);
            }

            if (version.Major == 1 &&
                version.Minor == 0 &&
                version.Patch == 0)
            {
                if (version.PreReleaseLabel.StartsWith("preview1") ||
                    version.PreReleaseLabel.StartsWith("preview2"))
                {
                    return(true);
                }
            }

            return(false);
        }
        public DotNetVersion GetVersion(string workingDirectory = null)
        {
            // Ensure that we set the DOTNET_CLI_UI_LANGUAGE environment variable to "en-US" before
            // running 'dotnet --version'. Otherwise, we may get localized results.
            var originalValue = Environment.GetEnvironmentVariable(DOTNET_CLI_UI_LANGUAGE);

            Environment.SetEnvironmentVariable(DOTNET_CLI_UI_LANGUAGE, "en-US");

            try
            {
                Process process;
                try
                {
                    process = Start("--version", workingDirectory);
                }
                catch
                {
                    return(DotNetVersion.FailedToStartError);
                }

                if (process.HasExited)
                {
                    return(DotNetVersion.FailedToStartError);
                }

                var lines = new List <string>();
                process.OutputDataReceived += (_, e) =>
                {
                    if (!string.IsNullOrWhiteSpace(e.Data))
                    {
                        lines.Add(e.Data);
                    }
                };

                process.ErrorDataReceived += (_, e) =>
                {
                    if (!string.IsNullOrWhiteSpace(e.Data))
                    {
                        lines.Add(e.Data);
                    }
                };

                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                process.WaitForExit();

                return(DotNetVersion.Parse(lines));
            }
            finally
            {
                Environment.SetEnvironmentVariable(DOTNET_CLI_UI_LANGUAGE, originalValue);
            }
        }