コード例 #1
0
        public DotNetInfo GetInfo(string workingDirectory = null)
        {
            const string DOTNET_CLI_UI_LANGUAGE = nameof(DOTNET_CLI_UI_LANGUAGE);

            // Ensure that we set the DOTNET_CLI_UI_LANGUAGE environment variable to "en-US" before
            // running 'dotnet --info'. 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("--info", workingDirectory);
                }
                catch
                {
                    return(DotNetInfo.Empty);
                }

                if (process.HasExited)
                {
                    return(DotNetInfo.Empty);
                }

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

                process.BeginOutputReadLine();

                process.WaitForExit();

                return(DotNetInfo.Parse(lines));
            }
            finally
            {
                Environment.SetEnvironmentVariable(DOTNET_CLI_UI_LANGUAGE, originalValue);
            }
        }
コード例 #2
0
        private DotNetCliService(string dotnetPath = null)
        {
            this._locks     = new ConcurrentDictionary <string, object>();
            this._semaphore = new SemaphoreSlim(Environment.ProcessorCount / 2);
            this._console   = IoC.Get <IConsole>();

            if (dotnetPath != null)
            {
                _dotnetPath = dotnetPath;
            }
            else
            {
                SetDotNetPath("");
            }

            _info = GetInfo();
        }