Exemple #1
0
        private int GetDotnetMajorVersion()
        {
            var result = ProcessHelpers.RunProcess("dotnet", "--version", Path.GetDirectoryName(_dte.Solution.FileName));

            if (result.exitCode != 0)
            {
                throw new InvalidOperationException($"Unable to detect current dotnet version (\"dotnet --version\" exited with code {result.exitCode})");
            }

            if (result.output.Contains("."))
            {
                if (int.TryParse(result.output.Substring(0, result.output.IndexOf('.')), out int majorVersion))
                {
                    return(majorVersion);
                }
            }

            throw new InvalidOperationException($"Unable to detect current dotnet version (\"dotnet --version\" returned \"{result.output}\")");
        }