예제 #1
0
        private MsBuildResult Build(TestSiteDeployerOptions options)
        {
            var properties = new Dictionary<string, string>
            {
                {"Configuration", options.BuildConfiguration},
                {"SolutionDir", options.SolutionDir}
            };

            if (!string.IsNullOrWhiteSpace(options.TransformationConfiguration))
                properties.Add("ProjectConfigTransformFileName", "Web." + options.TransformationConfiguration + ".config");

            if (options.AdditionalBuildProperties != null)
                foreach (var property in options.AdditionalBuildProperties)
                    properties.Add(property.Key, property.Value);

            using (TemporaryFile defaultLogFile = new TemporaryFile(), errorLogFile = new TemporaryFile())
            {
                var path = options.MsBuildExePathResolver(options.MsBuildToolsVersion, options.Use64BitMsBuild);

                var additionalLoggers = options.AdditionalMsBuildFileLoggers != null &&
                                        options.AdditionalMsBuildFileLoggers.Any()
                    ? string.Join(" ", options.AdditionalMsBuildFileLoggers.Select((l, i) => l.GetLoggerString(i + 3)))
                    : "";

                var arguments = string.Format(
                        @"""{0}"" ""/p:{1}"" ""/t:{2}"" ""/v:{3}"" /fl1 ""/flp1:{4}"" /fl2 ""/flp2:{5}"" {6}",
                        options.ProjectFilePath,
                        string.Join(";", properties.Select(kvp => kvp.Key + "=" + kvp.Value)),
                        string.Join(";", options.BuildTargets),
                        options.MsBuildVerbosity,
                        string.Format("LogFile={0};Verbosity={1}", defaultLogFile.Path, options.MsBuildVerbosity),
                        string.Format("LogFile={0};ErrorsOnly", errorLogFile.Path),
                        additionalLoggers
                        )
                    // Fix escaping, since \" would lead to errors (since it would escape the quotes).
                    // This happens mostly with directory properties (e.g. SolutionDir) which should end with a \.
                        .Replace(@"\""", @"\\""");

                var process = Process.Start(new ProcessStartInfo(path, arguments) { CreateNoWindow = !options.ShowMsBuildWindow, UseShellExecute = false });
                Trace.Assert(process != null, "process != null");
                process.WaitForExit();

                return process.ExitCode == 0
                        ? MsBuildResult.Success(defaultLogFile.GetContents())
                        : MsBuildResult.Failure(defaultLogFile.GetContents(), errorLogFile.GetContents());
            }
        }
예제 #2
0
        private MsBuildResult Build(TestSiteDeployerOptions options)
        {
            var projectFilePath = Path.Combine(options.ProjectDir, options.ProjectFileName);

            var properties = new Dictionary<string, string>();
            properties.Add("Configuration", options.BuildConfiguration);

            if (!string.IsNullOrWhiteSpace(options.SolutionDir))
                properties.Add("SolutionDir", options.SolutionDir);

            if (!string.IsNullOrWhiteSpace(options.ProjectDir) && options.ProjectDirSetByUser)
                properties.Add("ProjectDir", options.ProjectDir);

            if (!string.IsNullOrWhiteSpace(options.TransformationConfiguration))
                properties.Add("ProjectConfigTransformFileName", "Web." + options.TransformationConfiguration + ".config");

            if (options.AdditionalBuildProperties != null)
                foreach (var property in options.AdditionalBuildProperties)
                    properties.Add(property.Key, property.Value);

            using (TemporaryFile normalLogFile = new TemporaryFile(), errorLogFile = new TemporaryFile())
            {
                var path = options.MsBuildExePathResolver(options.MsBuildToolsVersion, options.Use64BitMsBuild);
                var arguments = string.Format(
                        "{0} /p:{1} /t:{2} /fl1 /flp1:{3} /fl2 /flp2:{4}",
                        projectFilePath,
                        string.Join(";", properties.Select(kvp => kvp.Key + "=" + kvp.Value)),
                        string.Join(";", options.BuildTargets),
                        string.Format("LogFile={0};Verbosity=Normal", normalLogFile.Path),
                        string.Format("LogFile={0};ErrorsOnly", errorLogFile.Path)
                        );

                var process = Process.Start(new ProcessStartInfo(path, arguments) { CreateNoWindow = !options.ShowMsBuildWindow, UseShellExecute = false });
                Trace.Assert(process != null, "process != null");
                process.WaitForExit();

                return process.ExitCode == 0
                        ? MsBuildResult.Success(normalLogFile.GetContents())
                        : MsBuildResult.Failure(normalLogFile.GetContents(), errorLogFile.GetContents());
            }
        }