コード例 #1
0
        private void BuildProjectWithDotNet()
        {
            string properties = string.Empty;

            if (_packArgs.Properties.Any())
            {
                foreach (var property in _packArgs.Properties)
                {
                    if (property.Key.Equals(Configuration, StringComparison.OrdinalIgnoreCase))
                    {
                        properties = $"-c {property.Value}";
                    }
                }
            }

            if (!string.IsNullOrEmpty(_packArgs.BasePath))
            {
                string basePath = Path.GetFullPath(_packArgs.BasePath);
                properties += $" -b \"{basePath}\"";
            }

            if (!string.IsNullOrEmpty(_packArgs.Suffix))
            {
                properties += $" --version-suffix {_packArgs.Suffix}";
            }

            string dotnetLocation = NuGetEnvironment.GetDotNetLocation();

            var processStartInfo = new ProcessStartInfo
            {
                UseShellExecute        = false,
                FileName               = dotnetLocation,
                Arguments              = $"build {properties}",
                WorkingDirectory       = _packArgs.CurrentDirectory,
                RedirectStandardOutput = false,
                RedirectStandardError  = false
            };

            int result;

            using (var process = Process.Start(processStartInfo))
            {
                process.WaitForExit();

                result = process.ExitCode;
            }

            if (0 != result)
            {
                // If the build fails, report the error
                throw new Exception(String.Format(CultureInfo.CurrentCulture, Strings.Error_BuildFailed, processStartInfo.FileName, processStartInfo.Arguments));
            }
        }