Ejemplo n.º 1
0
        public void when_executing_task_then_succeeds(bool useCompiledTasks)
        {
            var outputFile = Path.GetTempFileName();

            var task = new GenerateTasksFile
            {
                BuildEngine = engine,
                TasksName   = Path.GetFileNameWithoutExtension(outputFile),
                OutputPath  = Path.GetDirectoryName(outputFile),
                License     = @"
	The MIT License (MIT)

	Copyright (c) 2015 Mobile Essentials
",
                References  = XDocument.Load(@"..\..\..\TaskInliner\TaskInliner.csproj")
                              .Root.Descendants(xmlns + "Reference")
                              .Select(x => x.Attribute("Include").Value)
                              .Select(x => new TaskItem(x)).ToArray(),
                SourceTasks = new ITaskItem[] { new TaskItem(@"..\..\..\TaskInliner\GenerateTasksFile.cs") },
            };

            File.Copy("MSBuilder.TaskInliner.dll", Path.ChangeExtension(outputFile, ".dll"));

            Assert.True(task.Execute());

            var xmlProject = ProjectRootElement.Create();

            xmlProject.DefaultTargets = "Build";
            xmlProject.AddImport(task.TasksFile);
            var taskXml = xmlProject.AddTarget("Build")
                          .AddTask("GenerateTasksFile");

            var prjFile = Path.GetTempFileName();

            taskXml.SetParameter("TasksName", Path.GetFileNameWithoutExtension(prjFile));
            taskXml.SetParameter("OutputPath", Path.GetDirectoryName(prjFile));
            taskXml.SetParameter("References", "@(Reference)");
            taskXml.SetParameter("SourceTasks", "@(Compile)");

            var tempFile = Path.GetTempFileName();

            Console.WriteLine(tempFile);
            xmlProject.Save(tempFile);

            var psi = new ProcessStartInfo
            {
                CreateNoWindow         = true,
                UseShellExecute        = false,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
                FileName  = Path.Combine(MSBuildPath, "MSBuild.exe"),
                Arguments = (useCompiledTasks ? "/p:UseCompiledTasks=true " : "/p:UseCompiledTasks=false ") +
                            tempFile
            };

            var proc   = Process.Start(psi);
            var stdout = proc.StandardOutput.ReadToEnd().Trim();
            var errors = proc.StandardError.ReadToEnd().Trim();

            if (errors.Length > 0)
            {
                Assert.True(false, errors);
            }

            proc.WaitForExit();

            Assert.True(proc.ExitCode == 0, stdout);
        }
Ejemplo n.º 2
0
        public void when_executing_task_then_succeeds(bool useCompiledTasks)
        {
            var outputFile = Path.GetTempFileName();

            var task = new GenerateTasksFile
            {
                BuildEngine = engine,
                TasksName = Path.GetFileNameWithoutExtension(outputFile),
                OutputPath = Path.GetDirectoryName(outputFile),
                License = @"
            The MIT License (MIT)

            Copyright (c) 2015 Mobile Essentials
            ",
                References = XDocument.Load(@"..\..\..\TaskInliner\TaskInliner.csproj")
                    .Root.Descendants(xmlns + "Reference")
                    .Select(x => x.Attribute("Include").Value)
                    .Select(x => new TaskItem(x)).ToArray(),
                SourceTasks = new ITaskItem[] { new TaskItem(@"..\..\..\TaskInliner\GenerateTasksFile.cs") },
            };

            File.Copy("MSBuilder.TaskInliner.dll", Path.ChangeExtension(outputFile, ".dll"));

            Assert.True(task.Execute());

            var xmlProject = ProjectRootElement.Create();
            xmlProject.DefaultTargets = "Build";
            xmlProject.AddImport(task.TasksFile);
            var taskXml = xmlProject.AddTarget("Build")
                .AddTask("GenerateTasksFile");

            var prjFile = Path.GetTempFileName();

            taskXml.SetParameter("TasksName", Path.GetFileNameWithoutExtension(prjFile));
            taskXml.SetParameter("OutputPath", Path.GetDirectoryName(prjFile));
            taskXml.SetParameter("References", "@(Reference)");
            taskXml.SetParameter("SourceTasks", "@(Compile)");

            var tempFile = Path.GetTempFileName();
            Console.WriteLine(tempFile);
            xmlProject.Save(tempFile);

            var psi = new ProcessStartInfo
            {
                CreateNoWindow = true,
                UseShellExecute = false,
                RedirectStandardOutput = true,
                RedirectStandardError = true,
                FileName = Path.Combine(MSBuildPath, "MSBuild.exe"),
                Arguments = (useCompiledTasks ? "/p:UseCompiledTasks=true " : "/p:UseCompiledTasks=false ") +
                    tempFile
            };

            var proc = Process.Start(psi);
            var stdout = proc.StandardOutput.ReadToEnd().Trim();
            var errors = proc.StandardError.ReadToEnd().Trim();
            if (errors.Length > 0)
                Assert.True(false, errors);

            proc.WaitForExit();

            Assert.True(proc.ExitCode == 0, stdout);
        }