/// <summary>
        /// Assert that the log doesn't contain the given string.
        /// First check if the string is in the log string. If not
        /// than make sure it is also not in the MockLogger
        /// </summary>
        internal void AssertLogDoesntContain(string contains)
        {
            string logText;

            lock (_lockObj)
            {
                logText = _log.ToString();
            }

            if (_output == null)
            {
                Console.WriteLine(logText);
            }
            else
            {
                _output.WriteLine(logText);
            }

            Assert.Equal(-1, logText.IndexOf(contains, StringComparison.OrdinalIgnoreCase));

            // If we do not contain this string than pass it to
            // MockLogger. Since MockLogger is also registered as
            // a logger it may have this string.
            MockLogger.AssertLogDoesntContain(contains);
        }
        public void FailedTargets()
        {
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectFailure(@"

                <Project DefaultTargets=`build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`build` >
	                    <CallTarget Targets=`a; b; c` />
                    </Target>
                    <Target Name=`a` >
	                    <Message Text=`Inside A` />
                    </Target>
                    <Target Name=`b` >
	                    <Error Text=`Inside B` />
                    </Target>
                    <Target Name=`c` >
	                    <Message Text=`Inside C` />
                    </Target>
                </Project>
                ");

            logger.AssertLogContains("Inside A");
            logger.AssertLogContains("Inside B");

            // Target C should not have been run.
            logger.AssertLogDoesntContain("Inside C");
        }
Exemple #3
0
        /// <summary>
        /// Assert that the log doesn't contain the given string.
        /// First check if the string is in the log string. If not
        /// than make sure it is also not in the MockLogger
        /// </summary>
        /// <param name="contains"></param>
        internal void AssertLogDoesntContain(string contains)
        {
            if (_output == null)
            {
                Console.WriteLine(_log);
            }

            if (_upperLog == null)
            {
                _upperLog = _log.ToString().ToUpperInvariant();
            }

            Assert.False(_upperLog.Contains
                         (
                             contains.ToUpperInvariant()
                         ));

            // If we do not contain this string than pass it to
            // MockLogger. Since MockLogger is also registered as
            // a logger it may have this string.
            _mockLogger.AssertLogDoesntContain
            (
                contains
            );
        }
Exemple #4
0
        /// <summary>
        /// Assert that the log doesn't contain the given string.
        /// First check if the string is in the log string. If not
        /// than make sure it is also not in the MockLogger
        /// </summary>
        internal void AssertLogDoesntContain(string contains)
        {
            string logText;

            lock (_lockObj)
            {
                logText = _log.ToString();
            }

            if (_output == null)
            {
                Console.WriteLine(logText);
            }
            else
            {
                _output.WriteLine(logText);
            }

            logText.ShouldNotContain(contains, Case.Insensitive);

            // If we do not contain this string than pass it to
            // MockLogger. Since MockLogger is also registered as
            // a logger it may have this string.
            MockLogger.AssertLogDoesntContain(contains);
        }
Exemple #5
0
        public void EndToEndMultilineExec()
        {
            using (var env = TestEnvironment.Create(_output))
            {
                var testProject = env.CreateTestProjectWithFiles(@"<Project>
 <Target Name=""MultilineExec"">
  <Exec Command=""echo line 1
echo line 2
echo line 3"" />
   </Target>
</Project>");

                using (var buildManager = new BuildManager())
                {
                    MockLogger logger     = new MockLogger(_output, profileEvaluation: false, printEventsToStdout: false);
                    var        parameters = new BuildParameters()
                    {
                        Loggers = new[] { logger },
                    };

                    var collection = new ProjectCollection(
                        new Dictionary <string, string>(),
                        new[] { logger },
                        remoteLoggers: null,
                        ToolsetDefinitionLocations.Default,
                        maxNodeCount: 1,
                        onlyLogCriticalEvents: false,
                        loadProjectsReadOnly: true);

                    var project = collection.LoadProject(testProject.ProjectFile).CreateProjectInstance();

                    var request = new BuildRequestData(
                        project,
                        targetsToBuild: new[] { "MultilineExec" },
                        hostServices: null);

                    var result = buildManager.Build(parameters, request);

                    logger.AssertLogContains("line 2");
                    logger.AssertLogContains("line 3");

                    // To be correct, these need to be on separate lines, not
                    // all together on one.
                    logger.AssertLogDoesntContain("1 echo line");

                    result.OverallResult.ShouldBe(BuildResultCode.Success);
                }
            }
        }
Exemple #6
0
        public void PeekWithoutUsingTask()
        {
            string projectContents = @"
<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <Target Name='x'>
    <XmlPeek Query='abc' ContinueOnError='true' />
  </Target>
</Project>";

            // The task won't complete properly, but ContinueOnError converts the errors to warnings, so the build should succeed
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents);

            // Verify that the task was indeed found.
            logger.AssertLogDoesntContain("MSB4036");
        }
Exemple #7
0
        public void PokeWithoutUsingTask()
        {
            string projectContents = @"
<Project ToolsVersion='msbuilddefaulttoolsversion' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <Target Name='x'>
    <XmlPoke Value='abc' Query='def' XmlInputPath='ghi.jkl' ContinueOnError='true' />
  </Target>
</Project>";

            // The task will error, but ContinueOnError means that it will just be a warning.
            MockLogger logger = ObjectModelHelpers.BuildProjectExpectSuccess(projectContents);

            // Verify that the task was indeed found.
            logger.AssertLogDoesntContain("MSB4036");
        }
Exemple #8
0
        public void SetInputsOutputsIncremental()
        {
            string oldFile = null, newFile = null;

            try
            {
                oldFile = GetTempFiles(1, new DateTime(2005, 1, 1))[0];
                newFile = GetTempFiles(1, new DateTime(2006, 1, 1))[0];

                MockLogger logger = new MockLogger();
                Project    p      = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <Target Name=`t` Inputs=`" + newFile + "` Outputs=`" + oldFile + @"`>
                    <Message Text=`building target !!`/>                  
                </Target>
                </Project>
            ", logger);
                p.Build(new string[] { "t" });

                logger.AssertLogContains(new string[] { "building target !!" });
                logger.ClearLog();

                Target t = p.Targets["t"];

                // reverse inputs and outputs
                t.Inputs  = (string)oldFile;
                t.Outputs = (string)newFile;

                p.ResetBuildStatus();
                p.Build(new string[] { "t" });

                logger.AssertLogDoesntContain("building target !!");
            }
            finally
            {
                DeleteTempFiles(new string[] { oldFile });
                DeleteTempFiles(new string[] { newFile });
            }
        }
Exemple #9
0
        /// <summary>
        /// Assert that the log doesnt contain the given string.
        /// First check if the string is in the log string. If not
        /// than make sure it is also not in the MockLogger
        /// </summary>
        /// <param name="contains"></param>
        internal void AssertLogDoesntContain(string contains)
        {
            if (upperLog == null)
            {
                upperLog = log;
                upperLog = upperLog.ToUpperInvariant();
            }

            Assertion.Assert
            (
                !upperLog.Contains
                (
                    contains.ToUpperInvariant()
                )
            );

            // If we do not contain this string than pass it to
            // MockLogger. Since MockLogger is also registered as
            // a logger it may have this string.
            mockLogger.AssertLogDoesntContain
            (
                contains
            );
        }
Exemple #10
0
        public void TargetStopOnFirstFailureBuildInParallel()
        {
            string project1 = ObjectModelHelpers.CreateTempFileOnDisk(@"
                   <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                   <Target Name='T1'>
                          <Message Text='Proj2 T1 message'/>
                      </Target>
                    <Target Name='T2'>
                          <Message Text='Proj2 T2 message'/>
                      </Target>
                    <Target Name='T3'>
                           <Error Text='Error'/>
                      </Target>
                    </Project>
                  ");

            try
            {
                ITaskItem[] projects = new ITaskItem[]
                {
                    new TaskItem(project1)
                };
                for (int i = 0; i < 6; i++)
                {
                    bool stopOnFirstFailure = false;
                    bool runEachTargetSeparately = false;
                    string target1 = String.Empty;
                    string target2 = String.Empty;
                    string target3 = String.Empty;

                    switch (i)
                    {
                        case 0:
                            stopOnFirstFailure = true;
                            runEachTargetSeparately = true;
                            target1 = "T1";
                            target2 = "T2";
                            target3 = "T3";
                            break;
                        case 1:
                            stopOnFirstFailure = true;
                            runEachTargetSeparately = true;
                            target1 = "T1";
                            target2 = "T3";
                            target3 = "T2";
                            break;
                        case 2:
                            stopOnFirstFailure = false;
                            runEachTargetSeparately = true;
                            target1 = "T1";
                            target2 = "T3";
                            target3 = "T2";
                            break;
                        case 3:
                            stopOnFirstFailure = true;
                            target1 = "T1";
                            target2 = "T2";
                            target3 = "T3";
                            break;
                        case 4:
                            stopOnFirstFailure = true;
                            target1 = "T1";
                            target2 = "T3";
                            target3 = "T2";
                            break;
                        case 5:
                            stopOnFirstFailure = false;
                            target1 = "T1";
                            target2 = "T3";
                            target3 = "T2";
                            break;
                    }

                    string parentProjectContents = @"
                        <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                            <ItemGroup>
                                <Projects Include=`" + project1 + @"` />
                            </ItemGroup>

                            <ItemGroup>
                                <Targets Include=`" + target1 + @"` />
                                <Targets Include=`" + target2 + @"` />
                                <Targets Include=`" + target3 + @"` />
                            </ItemGroup>

                            <Target Name=`Build` Returns=`@(Outputs)`>
                                <MSBuild Projects=`@(Projects)` Targets=`@(Targets)` StopOnFirstFailure=`" + stopOnFirstFailure.ToString() + @"` RunEachTargetSeparately=`" + runEachTargetSeparately.ToString() + @"`>
                                    <Output TaskParameter=`TargetOutputs` ItemName=`Outputs` />
                                </MSBuild>
                            </Target>
                        </Project>";

                    MockLogger logger = new MockLogger();
                    Project p = ObjectModelHelpers.CreateInMemoryProject(parentProjectContents, logger);
                    bool success = p.Build();

                    switch (i)
                    {
                        case 0:
                            // Test the case where the error is in the last project and RunEachTargetSeparately = true
                            logger.AssertLogContains("Proj2 T1 message");
                            logger.AssertLogContains("Proj2 T2 message");
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingTargets"));
                            break;
                        case 1:
                            // Test the case where the error is in the second target out of 3.
                            logger.AssertLogContains("Proj2 T1 message");
                            logger.AssertLogContains(AssemblyResources.GetString("MSBuild.SkippingRemainingTargets"));
                            logger.AssertLogDoesntContain("Proj2 T2 message");
                            // The build should fail as the first project has an error
                            break;
                        case 2:
                            // Test case where error is in second last target but stopOnFirstFailure is false
                            logger.AssertLogContains("Proj2 T1 message");
                            logger.AssertLogContains("Proj2 T2 message");
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingTargets"));
                            break;
                        // Test the cases where RunEachTargetSeparately is false. In these cases all of the targets should be submitted at once
                        case 3:
                            // Test the case where the error is in the last project and RunEachTargetSeparately = true
                            logger.AssertLogContains("Proj2 T1 message");
                            logger.AssertLogContains("Proj2 T2 message");
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingTargets"));
                            // The build should fail as the first project has an error
                            break;
                        case 4:
                            // Test the case where the error is in the second target out of 3.
                            logger.AssertLogContains("Proj2 T1 message");
                            logger.AssertLogDoesntContain("Proj2 T2 message");
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingTargets"));
                            // The build should fail as the first project has an error
                            break;
                        case 5:
                            // Test case where error is in second last target but stopOnFirstFailure is false
                            logger.AssertLogContains("Proj2 T1 message");
                            logger.AssertLogDoesntContain("Proj2 T2 message");
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingTargets"));
                            break;
                    }

                    // The build should fail as the first project has an error
                    Assert.False(success, "Iteration of i:" + i + "Build Succeeded.  See 'Standard Out' tab for details.");
                }
            }
            finally
            {
                File.Delete(project1);
            }
        }
Exemple #11
0
        public void FilterItemPreviouslyModified2()
        {
            MockLogger logger = new MockLogger();
            Project p = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <ItemGroup>
                    <x Include=`a`/>
                  </ItemGroup>
                  <Target Name=`t`>
                    <ItemGroup>
                      <x>
                        <m1>1</m1>
                      </x>
                      <x>
                        <m1 Condition=`'%(x.m1)'=='1'`>2</m1>
                      </x>  
                    </ItemGroup>
                    <Message Text=`[%(x.m1)]`/>
                  </Target>
                </Project>
            ", logger);
            p.Build(new string[] { "t" });

            logger.AssertLogDoesntContain("[1]");
            logger.AssertLogContains("[2]");
        }
Exemple #12
0
        public void TaskOutputSpecifiedButNotSupported()
        {
            MockLogger logger = new MockLogger();
            string projectFileContents = @"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`Build`>
                        <Message Text=`Building...`>
                            <Output TaskParameter=`NotSupported` ItemName=`MyItem` />
                        </Message>
                        <Message Text=`Got Here!` />
                    </Target>
                </Project>";

            Project project = ObjectModelHelpers.CreateInMemoryProject(projectFileContents, logger);
            project.Build(null, null);

            logger.AssertLogContains("MSB4131");
            logger.AssertLogDoesntContain("Got Here!");
            Assertion.Assert("MSBuild should have logged an error because the task does not provide the given output parameter!", logger.ErrorCount > 0);
        }
        public void AnyCPULibraryProjectIsNot32BitPreferred()
        {
            string file = null;
            string outputPath = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString("N");

            try
            {
                file = Helpers.CreateFiles("class1.cs")[0];

                MockLogger logger = new MockLogger();

                Project project = ObjectModelHelpers.CreateInMemoryProject(
                    @"
                   <Project DefaultTargets=`Build` ToolsVersion=`4.0` xmlns=`msbuildnamespace`>
                      <PropertyGroup>
                        <OutputPath>" + outputPath + @"</OutputPath>
                        <AssemblyName>MyAssembly</AssemblyName>
                        <OutputType>Library</OutputType>
                        <Configuration>Debug</Configuration>
                        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
                      </PropertyGroup>
                      <ItemGroup>
                        <Compile Include=`" + file + @"` />
                      </ItemGroup>
                      <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.Targets` />
                    </Project>
                ",
                 logger
                 );

                project.Build();

                logger.AssertLogDoesntContain(" /platform:");
            }
            finally
            {
                if (file != null)
                {
                    File.Delete(file);
                }

                ObjectModelHelpers.DeleteDirectory(outputPath);
            }
        }
        public void AnyCPUWinMDObjProjectIsNot32BitPreferred()
        {
            string file = null;
            string outputPath = Path.GetTempPath() + "\\" + Guid.NewGuid().ToString("N");

            try
            {
                file = Helpers.CreateFiles("class1.cs")[0];

                MockLogger logger = new MockLogger();

                Project project = ObjectModelHelpers.CreateInMemoryProject(
                    @"
                   <Project DefaultTargets=`Build` ToolsVersion=`4.0` xmlns=`msbuildnamespace`>
                      <PropertyGroup>
                        <OutputPath>" + outputPath + @"</OutputPath>
                        <AssemblyName>MyAssembly</AssemblyName>
                        <OutputType>winmdobj</OutputType>
                        <Configuration>Debug</Configuration>
                      </PropertyGroup>
                      <!-- For dealing with the case where the Jupiter targets do not exist, in order to follow the appropriate codepaths in the standard managed
                           we need to be .NET 4.5 or greater -->
                      <PropertyGroup Condition=`!Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets')`>
                        <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
                      </PropertyGroup>
                      <ItemGroup>
                        <Compile Include=`" + file + @"` />
                      </ItemGroup>
                      <Import Project=`$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets` Condition=`Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets')` />
                      <!-- Fall back to CSharp targets for the sake of this test if the Jupiter targets don't exist, since what we're testing can be equally well resolved by either -->
                      <Import Project=`$(MSBuildToolsPath)\Microsoft.CSharp.Targets` Condition=`!Exists('$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v1.0\Microsoft.Windows.UI.Xaml.CSharp.targets')` />
                   </Project>
                ",
                 logger
                 );

                project.Build();

                logger.AssertLogDoesntContain(" /platform:");
            }
            finally
            {
                if (file != null)
                {
                    File.Delete(file);
                }

                ObjectModelHelpers.DeleteDirectory(outputPath);
            }
        }
Exemple #15
0
        public void OverridePropertiesInInferredCreateProperty()
        {
            string[] files = null;
            try
            {
                files = ObjectModelHelpers.GetTempFiles(2, new DateTime(2005, 1, 1));

                MockLogger logger = new MockLogger();
                Project p = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <ItemGroup>
                    <i Include=`" + files[0] + "`><output>" + files[1] + @"</output></i>
                  </ItemGroup> 
                  <ItemGroup>
                     <EmbeddedResource Include='a.resx'>
                    <LogicalName>foo</LogicalName>
                      </EmbeddedResource>
                        <EmbeddedResource Include='b.resx'>
                        <LogicalName>bar</LogicalName>
                    </EmbeddedResource>
                        <EmbeddedResource Include='c.resx'>
                        <LogicalName>barz</LogicalName>
                    </EmbeddedResource>
                    </ItemGroup>
                  <Target Name=`t2` DependsOnTargets=`t`>
                    <Message Text=`final:[$(LinkSwitches)]`/>   
                  </Target>
                  <Target Name=`t` Inputs=`%(i.Identity)` Outputs=`%(i.Output)`>
                    <Message Text=`start:[Hello]`/>
                    <CreateProperty Value=""@(EmbeddedResource->'/assemblyresource:%(Identity),%(LogicalName)', ' ')""
                                     Condition=""'%(LogicalName)' != '' "">
                         <Output TaskParameter=""Value"" PropertyName=""LinkSwitches""/>
                    </CreateProperty>
                    <Message Text=`end:[hello]`/>                    
                </Target>
                </Project>
            ", logger);
                p.Build(new string[] { "t2" });

                // We should only see messages from the second target, as the first is only inferred
                logger.AssertLogDoesntContain("start:");
                logger.AssertLogDoesntContain("end:");

                logger.AssertLogContains(new string[] { "final:[/assemblyresource:c.resx,barz]" });
                logger.AssertLogDoesntContain( ResourceUtilities.FormatResourceString("TaskStarted", "CreateProperty"));
                logger.AssertLogContains(new string[] { ResourceUtilities.FormatResourceString("PropertyOutputOverridden", "LinkSwitches", "/assemblyresource:a.resx,foo", "/assemblyresource:b.resx,bar") });
                logger.AssertLogContains(new string[] { ResourceUtilities.FormatResourceString("PropertyOutputOverridden", "LinkSwitches", "/assemblyresource:b.resx,bar", "/assemblyresource:c.resx,barz") });
            }
            finally
            {
                ObjectModelHelpers.DeleteTempFiles(files);
            }
        }
        public void SetInputsOutputsIncremental()
        {
            string oldFile = null, newFile = null;
            try
            {
                oldFile = GetTempFiles(1, new DateTime(2005, 1, 1))[0];
                newFile = GetTempFiles(1, new DateTime(2006, 1, 1))[0];

                MockLogger logger = new MockLogger();
                Project p = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <Target Name=`t` Inputs=`" + newFile + "` Outputs=`" + oldFile + @"`>
                    <Message Text=`building target !!`/>                  
                </Target>
                </Project>
            ", logger);
                p.Build(new string[] { "t" });

                logger.AssertLogContains(new string[] { "building target !!" });
                logger.ClearLog();

                Target t = p.Targets["t"];

                // reverse inputs and outputs
                t.Inputs = (string)oldFile;
                t.Outputs = (string)newFile;

                p.ResetBuildStatus();
                p.Build(new string[] { "t" });

                logger.AssertLogDoesntContain("building target !!");
                

            }
            finally
            {
                DeleteTempFiles(new string[] { oldFile });
                DeleteTempFiles(new string[] { newFile });
            }
        }
Exemple #17
0
        public void StopOnFirstFailureandBuildInParallelMultipleNode()
        {
            string project1 = ObjectModelHelpers.CreateTempFileOnDisk(@"
                  <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                      <Target Name='msbuild'>
                          <Error Text='Error'/>
                      </Target>
                  </Project>
                  ");

            string project2 = ObjectModelHelpers.CreateTempFileOnDisk(@"
                   <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                       <Target Name='msbuild'>
                           <Message Text='SecondProject'/>
                       </Target>
                    </Project>
                  ");

            try
            {
                // Test the various combinations of BuildInParallel and StopOnFirstFailure when the msbuild task is told there are multiple nodes 
                // running in the system
                for (int i = 0; i < 4; i++)
                {
                    bool buildInParallel = false;
                    bool stopOnFirstFailure = false;

                    // first set up the project being built. 
                    switch (i)
                    {
                        case 0:
                            buildInParallel = true;
                            stopOnFirstFailure = true;
                            break;
                        case 1:
                            buildInParallel = true;
                            stopOnFirstFailure = false;
                            break;
                        case 2:
                            buildInParallel = false;
                            stopOnFirstFailure = true;
                            break;
                        case 3:
                            buildInParallel = false;
                            stopOnFirstFailure = false;
                            break;
                    }

                    string parentProjectContents = @"
                        <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                            <ItemGroup>
                                <Projects Include=`" + project1 + @"` />
                                <Projects Include=`" + project2 + @"` />
                            </ItemGroup>

                            <Target Name=`Build` Returns=`@(Outputs)`>
                                <MSBuild Projects=`@(Projects)` Targets=`msbuild` BuildInParallel=`" + buildInParallel.ToString() + @"` StopOnFirstFailure=`" + stopOnFirstFailure.ToString() + @"`>
                                    <Output TaskParameter=`TargetOutputs` ItemName=`Outputs` />
                                </MSBuild>
                            </Target>
                        </Project>";

                    MockLogger logger = new MockLogger();
                    ProjectCollection pc = new ProjectCollection(null, new List<ILogger> { logger }, null, ToolsetDefinitionLocations.Registry | ToolsetDefinitionLocations.ConfigurationFile, 2, false);
                    Project p = ObjectModelHelpers.CreateInMemoryProject(pc, parentProjectContents, logger);
                    bool success = p.Build();
                    switch (i)
                    {
                        case 0:
                            // Verify build did build second project which has the message SecondProject
                            logger.AssertLogContains("SecondProject");
                            // Verify the correct msbuild task messages are in the log
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingProjects"));
                            logger.AssertLogContains(AssemblyResources.GetString("MSBuild.NoStopOnFirstFailure"));
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.NotBuildingInParallel"));
                            break;
                        case 1:
                            // Verify setting BuildInParallel to true and StopOnFirstFailure to 
                            // false will cause no change in BuildInParallel
                            // Verify build did build second project which has the message SecondProject
                            logger.AssertLogContains("SecondProject");
                            // Verify the correct msbuild task messages are in the log
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingProjects"));
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.NoStopOnFirstFailure"));
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.NotBuildingInParallel"));
                            break;
                        case 2:
                            // Verify setting BuildInParallel to false and StopOnFirstFailure to 
                            // true will cause no change in BuildInParallel
                            // Verify build did not build second project which has the message SecondProject
                            logger.AssertLogDoesntContain("SecondProject");
                            // Verify the correct msbuild task messages are in the log
                            logger.AssertLogContains(AssemblyResources.GetString("MSBuild.SkippingRemainingProjects"));
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.NoStopOnFirstFailure"));
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.NotBuildingInParallel"));
                            break;

                        case 3:
                            // Verify setting BuildInParallel to false and StopOnFirstFailure to 
                            // false will cause no change in BuildInParallel
                            // Verify build did build second project which has the message SecondProject
                            logger.AssertLogContains("SecondProject");
                            // Verify the correct msbuild task messages are in the log
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingProjects"));
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.NoStopOnFirstFailure"));
                            logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.NotBuildingInParallel"));
                            break;
                    }
                    // The build should fail as the first project has an error
                    Assert.False(success, "Iteration of i " + i + " Build Succeeded.  See 'Standard Out' tab for details.");
                }
            }
            finally
            {
                File.Delete(project1);
                File.Delete(project2);
            }
        }
Exemple #18
0
        public void PropertiesInInferredBuildCreateProperty()
        {
            string[] files = null;
            try
            {
                files = ObjectModelHelpers.GetTempFiles(2, new DateTime(2005, 1, 1));

                MockLogger logger = new MockLogger();
                Project p = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <ItemGroup>
                    <i Include=`" + files[0] + "`><output>" + files[1] + @"</output></i>
                  </ItemGroup> 
                  <Target Name=`t2` DependsOnTargets=`t`>
                    <Message Text=`final:[$(p)]`/>                    
                  </Target>
                  <Target Name=`t` Inputs=`%(i.Identity)` Outputs=`%(i.Output)`>
                    <Message Text=`start:[$(p)]`/>
                    <CreateProperty Value='@(i)'>
                      <Output TaskParameter='Value' PropertyName='p'/>
                    </CreateProperty>
                    <Message Text=`end:[$(p)]`/>                    
                </Target>
                </Project>
            ", logger);
                p.Build(new string[] { "t2" });

                // We should only see messages from the second target, as the first is only inferred
                logger.AssertLogDoesntContain("start:");
                logger.AssertLogDoesntContain("end:");
                logger.AssertLogContains(new string[] { "final:[" + files[0] + "]" });
            }
            finally
            {
                ObjectModelHelpers.DeleteTempFiles(files);
            }
        }
Exemple #19
0
        public void SkipRemainingProjects()
        {
            string project1 = ObjectModelHelpers.CreateTempFileOnDisk(@"
                  <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                      <Target Name='msbuild'>
                          <Error Text='Error'/>
                      </Target>
                  </Project>
                  ");

            string project2 = ObjectModelHelpers.CreateTempFileOnDisk(@"
                   <Project xmlns='msbuildnamespace' ToolsVersion='msbuilddefaulttoolsversion'>
                       <Target Name='msbuild'>
                           <Message Text='SecondProject'/>
                       </Target>
                    </Project>
                  ");

            try
            {
                string parentProjectContents = @"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <ItemGroup>
                        <Projects Include=`" + project1 + @"` />
                    </ItemGroup>

                    <Target Name=`Build` Returns=`@(Outputs)`>
                        <MSBuild Projects=`@(Projects)` Targets=`msbuild` BuildInParallel=`false` StopOnFirstFailure=`true`>
                            <Output TaskParameter=`TargetOutputs` ItemName=`Outputs` />
                        </MSBuild>
                    </Target>
                </Project>";

                MockLogger logger = new MockLogger();
                ProjectCollection pc = new ProjectCollection(null, new List<ILogger> { logger }, null, ToolsetDefinitionLocations.Registry | ToolsetDefinitionLocations.ConfigurationFile, 2, false);
                Project p = ObjectModelHelpers.CreateInMemoryProject(pc, parentProjectContents, logger);
                bool success = p.Build();

                logger.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingProjects"));
                Assert.False(success); // "Build Succeeded.  See 'Standard Out' tab for details."

                parentProjectContents = @"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <ItemGroup>
                        <Projects Include=`" + project2 + @"` />
                        <Projects Include=`" + project1 + @"` />
                    </ItemGroup>

                    <Target Name=`Build` Returns=`@(Outputs)`>
                        <MSBuild Projects=`@(Projects)` Targets=`msbuild` BuildInParallel=`false` StopOnFirstFailure=`true`>
                            <Output TaskParameter=`TargetOutputs` ItemName=`Outputs` />
                        </MSBuild>
                    </Target>
                </Project>";

                MockLogger logger2 = new MockLogger();
                Project p2 = ObjectModelHelpers.CreateInMemoryProject(pc, parentProjectContents, logger2);
                bool success2 = p2.Build();
                logger2.AssertLogDoesntContain(AssemblyResources.GetString("MSBuild.SkippingRemainingProjects"));
                Assert.False(success2); // "Build Succeeded.  See 'Standard Out' tab for details."
            }
            finally
            {
                File.Delete(project1);
                File.Delete(project2);
            }
        }