コード例 #1
0
ファイル: Choose_Tests.cs プロジェクト: 3F/IeXod
        public void ChooseNotTaken()
        {
            Project p = ObjectModelHelpers.CreateInMemoryProject(@"

                <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>
                  <Choose>
                    <When Condition=`1==2`>
                      <PropertyGroup><a>aa</a></PropertyGroup>
                    </When>
                  </Choose>
                  <Target Name=`t`>
                    <Message Text=`[$(a)]`/>
                  </Target>
                </Project>
            ");

            p.Build(new string[] { "t" }, null);
            BuildPropertyGroup props = p.EvaluatedProperties;

            Assertion.Assert(props["a"] == null);
        }
コード例 #2
0
ファイル: Item_Tests.cs プロジェクト: 3F/IeXod
        public void InvalidItemMetadataNameInProject()
        {
            bool fExceptionCaught = false;

            try
            {
                Project p = ObjectModelHelpers.CreateInMemoryProject
                            (
                    "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
                    + "  <ItemGroup Condition=\"false\"><Chooses Include=\"blah\"><When/></Chooses></ItemGroup>"
                    + "  <Target Name=\"t\">"
                    + "    <Message Text=\"aa\"/>"
                    + "  </Target>"
                    + "</Project>"
                            );
            }
            catch (InvalidProjectFileException)
            {
                fExceptionCaught = true;
            }
            Assertion.Assert(fExceptionCaught);
        }
コード例 #3
0
ファイル: PropertyGroup_Tests.cs プロジェクト: 3F/IeXod
        public void RemovePropertyFromPropertyGroupThatIsntItsParent()
        {
            Project p = ObjectModelHelpers.CreateInMemoryProject(@"

                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>

                        <PropertyGroup>
                            <a>123</a>
                            <b>456</b>
                        </PropertyGroup>

                        <PropertyGroup>
                            <c>789</c>
                        </PropertyGroup>

                    </Project>

                ");

            BuildPropertyGroup[] propertyGroups = new BuildPropertyGroup[2];
            p.PropertyGroups.CopyTo(propertyGroups, 0);

            BuildPropertyGroup first  = propertyGroups[0].Count == 2 ? propertyGroups[0] : propertyGroups[1];
            BuildPropertyGroup second = propertyGroups[1].Count == 1 ? propertyGroups[1] : propertyGroups[0];

            BuildProperty property = null;

            foreach (BuildProperty tempProperty in first)
            {
                if (tempProperty.Name.Equals("a", StringComparison.OrdinalIgnoreCase))
                {
                    property = tempProperty;
                    break;
                }
            }

            //this should throw because the property comes from another property group
            second.RemoveProperty(property);
        }
コード例 #4
0
ファイル: TargetCollection_Tests.cs プロジェクト: 3F/IeXod
        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 });
            }
        }
コード例 #5
0
ファイル: BuildItemGroup_Tests.cs プロジェクト: 3F/IeXod
        public void MutualReferenceToMetadataQualified()
        {
            MockLogger logger = new MockLogger();
            Project    p      = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project xmlns=`msbuildnamespace`>
                  <ItemGroup>
                    <i Include=`i1`>
                      <m>m1</m>
                      <m>%(i.m);m2</m>
                      <m Condition='false'>%(m);m3</m> 
                    </i>
                  </ItemGroup> 
                  <Target Name=`t`>
                    <Message Text=`[%(i.m)]`/>
                  </Target>
                </Project>
            ", logger);

            p.Build("t");

            logger.AssertLogContains("[m1;m2]");
        }
コード例 #6
0
        public void TrueCondition()
        {
            MockLogger l = new MockLogger();
            Project    p = ObjectModelHelpers.CreateInMemoryProject(@"

                <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> 
                   <Target Name='CleanUp'>
                      <Message Text='CleanUp-was-called.'/>
                   </Target>
                   <Target Name='Build'>
                      <Error Text='This is an error.'/>
                      <OnError Condition=`'A'!='B'` ExecuteTargets='CleanUp'/>
                   </Target>
                </Project>",
                                                                    l
                                                                    );

            p.Build(new string [] { "Build" }, null);

            Assertion.Assert("Expected one error because 'Build' failed.", l.ErrorCount == 1);
            Assertion.Assert("The CleanUp target should have been called.", (l.FullLog.IndexOf("CleanUp-was-called") != -1));
        }
コード例 #7
0
        public void OnErrorSeesPropertiesAndItemsFromFirstTarget()
        {
            MockLogger l = new MockLogger();
            Project    p = ObjectModelHelpers.CreateInMemoryProject(@"

                <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> 

                   <Target Name='Build'>
                      <!-- Create a bunch of items and properties -->
                      <CreateItem Include='a1'>
                        <Output ItemName='i1' TaskParameter='Include'/>
                      </CreateItem> 
                      <ItemGroup>
                        <i1 Include='a2'/>
                      </ItemGroup> 
                      <CreateProperty Value='v1'>
                        <Output PropertyName='p1' TaskParameter='Value'/>
                      </CreateProperty>
                      <PropertyGroup>
                        <p2>v2</p2>
                      </PropertyGroup>

                      <Error Text='This is an error.'/>
                      <OnError ExecuteTargets='ErrorTarget'/>
                   </Target>

                   <Target Name='ErrorTarget'>
                      <Message Text='[@(i1)][$(p1)][$(p2)]'/>
                   </Target>

                </Project>",
                                                                    l
                                                                    );

            p.Build(new string[] { "Build" }, null);

            Assertion.Assert("Expected one error because 'Build' failed.", l.ErrorCount == 1);
            l.AssertLogContains("[a1;a2][v1][v2]");
        }
コード例 #8
0
        public void InvalidCharInPropertyNameInProject()
        {
            bool exceptionCaught = false;

            try
            {
                Project p = ObjectModelHelpers.CreateInMemoryProject
                            (
                    "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">"
                    + "  <PropertyGroup Condition=\"false\"><\u03A3/></PropertyGroup>"
                    + "  <Target Name=\"t\">"
                    + "    <Message Text=\"aa\"/>"
                    + "  </Target>"
                    + "</Project>"
                            );
            }
            catch (InvalidProjectFileException)
            {
                exceptionCaught = true;
            }
            Assertion.Assert(exceptionCaught);
        }
コード例 #9
0
        public void TestICollectionMethods()
        {
            Project project = ObjectModelHelpers.CreateInMemoryProject(string.Format(@"

                    <Project xmlns=`msbuildnamespace`>

                        <UsingTask TaskName=`net.r_eg.IeXod.UnitTests.Project_Tests.WashCar` AssemblyFile=`{0}` Condition=` true == true `/>
                        <UsingTask TaskName=`net.r_eg.IeXod.UnitTests.Project_Tests.Message` AssemblyName=`{1}` Condition=` false == true `/>

                        <Target Name=`Build`>
                            <WashCar/>
                        </Target>

                    </Project>

                ", new Uri(Assembly.GetExecutingAssembly().EscapedCodeBase).LocalPath, Assembly.GetExecutingAssembly().FullName));

            UsingTaskCollection usingTasks = project.UsingTasks;

            Assertion.AssertEquals(2, usingTasks.Count);

            UsingTask[] array = new UsingTask[2];
            usingTasks.CopyTo(array, 0);

            Assertion.AssertEquals(usingTasks[0], array[0]);
            Assertion.AssertEquals(usingTasks[1], array[1]);

            object[] arrayObjects = new object[2];
            usingTasks.CopyTo(arrayObjects, 0);

            Assertion.AssertEquals(usingTasks[0], arrayObjects[0]);
            Assertion.AssertEquals(usingTasks[1], arrayObjects[1]);

            Assertion.AssertEquals("net.r_eg.IeXod.UnitTests.Project_Tests.WashCar", usingTasks[0].TaskName);
            Assertion.AssertEquals("net.r_eg.IeXod.UnitTests.Project_Tests.Message", usingTasks[1].TaskName);

            Assert.IsFalse(usingTasks.IsSynchronized, "Expected IsSynchronized to be false");
            Assert.IsNotNull(usingTasks.SyncRoot, "Expected SynchRoot to not be null");
        }
コード例 #10
0
        public void ItemDefinitionForOtherItemType()
        {
            MockLogger logger = new MockLogger();
            Project    p      = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <ItemGroup>
                    <i Include='i1'/>
                  </ItemGroup>
                  <ItemDefinitionGroup>
                    <j>
                      <m>m1</m>
                    </j>
                  </ItemDefinitionGroup> 
                  <Target Name=`t`>
                    <Message Text=`[%(i.m)]`/>
                  </Target>
                </Project>
            ", logger);

            p.Build("t");

            logger.AssertLogContains("[]");
        }
コード例 #11
0
        public void EscapingInItemDefinitionInProject()
        {
            MockLogger logger = new MockLogger();
            Project    p      = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <ItemGroup>
                    <i Include='i1'/>
                  </ItemGroup>
                  <ItemDefinitionGroup Condition=`'%24'=='$'`>
                    <i Condition=`'%24'=='$'`>
                      <m Condition=`'%24'=='$'`>%24(xyz)</m>
                    </i>
                  </ItemDefinitionGroup> 
                  <Target Name=`t`>
                    <Message Text=`[%(i.m)]`/>
                  </Target>
                </Project>
            ", logger);

            p.Build("t");

            logger.AssertLogContains("[$(xyz)]");
        }
コード例 #12
0
ファイル: BuildItemGroup_Tests.cs プロジェクト: 3F/IeXod
        public void AddExistingItemAt()
        {
            MockLogger logger = new MockLogger();
            Project    p      = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project xmlns=`msbuildnamespace`>
                  <ItemDefinitionGroup>
                    <i>
                      <m>m1</m>
                    </i>
                  </ItemDefinitionGroup> 
                </Project>
            ", logger);

            BuildItemGroup group = p.AddNewItemGroup();
            BuildItem      item  = new BuildItem("i", "i1");

            group.AddExistingItemAt(0, item);
            Expander expander = new Expander(new BuildPropertyGroup());

            item.EvaluateAllItemMetadata(expander, ParserOptions.AllowPropertiesAndItemLists, null, null);

            Assertion.AssertEquals("m1", item.GetMetadata("m"));
        }
コード例 #13
0
ファイル: Item_Tests.cs プロジェクト: 3F/IeXod
        public void ItemMetadataShouldBeEvaluatedEarly()
        {
            string projectOriginalContents = @"
                <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>

                    <ItemGroup>
                        <CultureItem Include=`spanish`/>
                        <Compile Include=`a`>
                            <Culture>@(CultureItem)</Culture>
                        </Compile>
                        <CultureItem Include=`french`/>
                    </ItemGroup>
                
                </Project>
                ";

            Project project = ObjectModelHelpers.CreateInMemoryProject(projectOriginalContents);

            BuildItemGroup compileItems     = project.GetEvaluatedItemsByName("Compile");
            string         evaluatedCulture = compileItems[0].GetEvaluatedMetadata("Culture");

            Assertion.AssertEquals("Culture should be 'spanish'", "spanish", evaluatedCulture);
        }
コード例 #14
0
ファイル: BuildTask_Tests.cs プロジェクト: 3F/IeXod
        public void CatchDollarSignInOutputPropertyName()
        {
            string projectContents = @"

                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`t` >
                        <CreateProperty Value=`x`>
                            <Output TaskParameter=`Value` PropertyName=`$(x)`/>
                        </CreateProperty>
                    </Target>
                </Project>
                ";

            Project    p = ObjectModelHelpers.CreateInMemoryProject(projectContents);
            MockLogger l = new MockLogger();

            p.ParentEngine.RegisterLogger(l);

            p.Build(new string[] { "t" }, null);
            string warning = String.Format(MockLogger.GetString("DollarSignInTaskOutputPropertyName"), "$(x)");

            Assertion.Assert(-1 != l.FullLog.IndexOf(warning));
        }
コード例 #15
0
ファイル: PropertyGroup_Tests.cs プロジェクト: 3F/IeXod
        public void SetGlobalPropertyAfterLoadBeforeBuild()
        {
            MockLogger logger = new MockLogger();

            Project project = ObjectModelHelpers.CreateInMemoryProject(@"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                        <Target Name=`log_property`>
                            <Message Text=`[$(p)]`/>
                        </Target>
                    </Project>
                ", logger);

            BuildPropertyGroup globals = project.GlobalProperties;

            // Set a property before building -- this should work
            BuildProperty p = new BuildProperty("p", "v1");

            globals.SetProperty(p);

            project.Build();

            logger.AssertLogContains("[v1]");
        }
コード例 #16
0
        public void DefinitionInImportedFile()
        {
            MockLogger logger       = new MockLogger();
            string     importedFile = null;

            try
            {
                importedFile = Path.GetTempFileName();
                File.WriteAllText(importedFile, @"
                <Project ToolsVersion='3.5' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                  <ItemDefinitionGroup>
                    <CppCompile>
                      <Defines>DEBUG</Defines>
                    </CppCompile>
                  </ItemDefinitionGroup> 
                </Project>
            ");
                Project p = ObjectModelHelpers.CreateInMemoryProject(@"
                    <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                      <ItemGroup>
                        <CppCompile Include='a.cpp'/>                      
                      </ItemGroup>
                      <Import Project='" + importedFile + @"'/>
                      <Target Name=`t`>
                        <Message Text=`[%(CppCompile.Identity)==%(CppCompile.Defines)]`/>
                      </Target>
                    </Project>
                ", logger);
                p.Build("t");

                logger.AssertLogContains("[a.cpp==DEBUG]");
            }
            finally
            {
                ObjectModelHelpers.DeleteTempFiles(new string[] { importedFile });
            }
        }
コード例 #17
0
        public void MetadataConditionOnItemDefinition()
        {
            MockLogger logger = new MockLogger();
            Project    p      = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <ItemGroup>
                    <i Include='i1'/>
                    <j Include='j1'/>
                  </ItemGroup>
                  <ItemDefinitionGroup>
                    <i>
                      <m>m1</m>
                    </i>
                    <j>
                      <n>n1</n>
                    </j>
                  </ItemDefinitionGroup> 
                  <ItemDefinitionGroup>
                    <i Condition=`'%(m)'=='m1'`>
                      <m>m2</m>
                    </i>
                    <!-- verify j metadata is distinct -->
                    <j Condition=`'%(j.n)'=='n1' and '%(n)'=='n1'`>
                      <n>n2</n>   
                    </j>
                  </ItemDefinitionGroup> 
                  <Target Name=`t`>
                    <Message Text=`[%(i.m)]`/>
                    <Message Text=`[%(j.n)]`/>
                  </Target>
                </Project>
            ", logger);

            p.Build("t");

            logger.AssertLogContains("[m2]", "[n2]");
        }
コード例 #18
0
ファイル: BuildTask_Tests.cs プロジェクト: 3F/IeXod
        public void EscapeOutputItemspecs()
        {
            string projectContents = @"

                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                    <Target Name=`t` >
                        <CreateItem Include=`%2520`><!-- should be a literal %20 not a space -->
                            <Output TaskParameter=`Include` ItemName=`Include`/>
                        </CreateItem>
                        <Message Text=`@(include)` Importance=`high`/>
                    </Target>
                </Project>
                ";

            Project    p = ObjectModelHelpers.CreateInMemoryProject(projectContents);
            MockLogger l = new MockLogger();

            p.ParentEngine.RegisterLogger(l);

            p.Build(new string[] { "t" }, null);
            Assertion.Assert(l.ErrorCount == 0);
            Assertion.Assert(l.WarningCount == 0);
            l.AssertLogContains("%20");
        }
コード例 #19
0
        public void ItemGroupInAPropertyCondition()
        {
            Project p = ObjectModelHelpers.CreateInMemoryProject(@"

                <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>

                    <ItemGroup>
                        <x Include=`x1`/>
                    </ItemGroup>

                    <PropertyGroup>
                        <a Condition=`@(x)=='x1'`>@(x)</a>
                    </PropertyGroup>

                    <Target Name=`t`>
                        <Message Text=`[$(a)]`/>
                    </Target>

                </Project>

            ");

            p.Build(new string[] { "t" }, null);
        }
コード例 #20
0
        public void ErrorTargetsContinueAfterErrorsInErrorHandler()
        {
            MockLogger l = new MockLogger();
            Project    p = ObjectModelHelpers.CreateInMemoryProject(@"

                <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> 
                   <Target Name='CleanUp1'>
                      <Message Text='CleanUp1-was-called.'/>
                      <Error Text='Error in CleanUp1.'/>
                   </Target>
                   <Target Name='CleanUp2'>
                      <Message Text='CleanUp2-was-called.'/>
                      <Error Text='Error in CleanUp2.'/>
                   </Target>
                   <Target Name='CleanUp3'>
                      <Message Text='CleanUp3-was-called.'/>
                      <Error Text='Error in CleanUp3.'/>
                   </Target>
                   <Target Name='CoreBuild'>
                      <Error Text='This is an error.'/>
                      <OnError ExecuteTargets='CleanUp1;CleanUp2'/>
                   </Target>
                   <Target Name='Build' DependsOnTargets='CoreBuild'>
                      <OnError ExecuteTargets='CleanUp3'/>
                   </Target>
                </Project>",
                                                                    l
                                                                    );

            p.Build(new string [] { "Build" }, null);

            Assertion.Assert("Four build errors expect: One from CoreBuild and on each from the error handlers.", l.ErrorCount == 4);
            Assertion.Assert("The CleanUp1 target should have been called.", (l.FullLog.IndexOf("CleanUp1-was-called") != -1));
            Assertion.Assert("The CleanUp2 target should have been called.", (l.FullLog.IndexOf("CleanUp2-was-called") != -1));
            Assertion.Assert("The CleanUp3 target should have been called.", (l.FullLog.IndexOf("CleanUp3-was-called") != -1));
        }
コード例 #21
0
        public void ItemsEmittedByTaskPickUpItemDefinitions()
        {
            MockLogger logger = new MockLogger();
            Project    p      = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <ItemDefinitionGroup>
                    <i>
                      <m>m1</m>
                      <n>n1</n>
                    </i>
                  </ItemDefinitionGroup> 
                  <Target Name=`t`>
                    <CreateItem Include=`i1` AdditionalMetadata=`n=n2`>
                      <Output ItemName=`i` TaskParameter=`Include`/>
                    </CreateItem>
                    <Message Text=`[%(i.m)][%(i.n)]`/>
                  </Target>
                </Project>
            ", logger);

            p.Build("t");

            logger.AssertLogContains("[m1][n2]");
        }
コード例 #22
0
        public void MutualReferenceToDefinition2()
        {
            MockLogger logger = new MockLogger();
            Project    p      = ObjectModelHelpers.CreateInMemoryProject(@"
                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                  <ItemDefinitionGroup>
                    <i>
                      <m>~%(n)~</m>
                      <n>n1</n>
                    </i>
                  </ItemDefinitionGroup> 
                    <ItemGroup>
                      <i Include=`i1`/>
                    </ItemGroup>   
                  <Target Name=`t`>
                    <Message Text=`[%(i.m)][%(i.n)]`/>
                  </Target>
                </Project>
            ", logger);

            p.Build("t");

            logger.AssertLogContains("[~~][n1]");
        }
コード例 #23
0
        public void TargetInProgressStateCustomSerialization()
        {
            Engine                   engine             = new Engine(@"c:\");
            Project                  project            = ObjectModelHelpers.CreateInMemoryProject(@"
                   <Project DefaultTargets=`t` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
                        <PropertyGroup>
                        <OutputPath>bin\Debug\</OutputPath>
                        <AssemblyName>MyAssembly</AssemblyName>
                        <OutputType>Exe</OutputType>
                        <Configuration>Debug</Configuration>
                      </PropertyGroup>
                      <ItemGroup>
                        <Compile Include=`Class1.cs` />
                        <EmbeddedResource Include=`Resource1.txt` />
                        <EmbeddedResource Include=`Resource2.resx` />
                      </ItemGroup>
                      <Target Name='t' DependsOnTargets='Build'/>
                    <Import Project=`$(MSBuildBinPath)\Microsoft.CSharp.Targets` />
                    </Project>
                ");
            EngineCallback           engineCallback     = new EngineCallback(engine);
            Target                   build              = project.Targets["Build"];
            List <ProjectBuildState> waitingBuildStates = null;

            int    handleId        = 1;
            string projectFileName = "ProjectFileName";

            string[] targetNames = new string[] { "t" };
            Dictionary <string, string> dictionary = null;
            int          requestId          = 1;
            BuildRequest request            = new BuildRequest(handleId, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false);
            ArrayList    targetNamesToBuild = new ArrayList();

            targetNamesToBuild.Add("t");
            ProjectBuildState initiatingRequest = new ProjectBuildState(request, targetNamesToBuild, new BuildEventContext(1, 2, 2, 2));

            initiatingRequest.AddBlockingTarget("Build");
            BuildRequest [] outstandingBuildRequests = null;
            string          projectName = "SuperTestProject";



            TargetInProgessState targetInProgress1 = new TargetInProgessState(
                engineCallback,
                build,
                waitingBuildStates,
                initiatingRequest,
                outstandingBuildRequests,
                projectName
                );

            targetInProgress1.ParentTargetsForBuildRequests = null;
            Assertion.AssertNull(targetInProgress1.ParentTargetsForBuildRequests);
            Assertion.Assert(!targetInProgress1.RequestedByHost);

            build   = project.Targets["t"];
            request = new BuildRequest(handleId, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false);
            request.IsExternalRequest = true;
            targetNamesToBuild.Add("t");
            initiatingRequest        = new ProjectBuildState(request, targetNamesToBuild, new BuildEventContext(1, 2, 2, 2));
            outstandingBuildRequests = new BuildRequest[] {
                new BuildRequest(1, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false),
                new BuildRequest(2, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false),
                new BuildRequest(3, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false),
                new BuildRequest(4, projectFileName, targetNames, (IDictionary)dictionary, null, requestId, false, false)
            };

            TargetInProgessState.TargetIdWrapper originalWrapper = new TargetInProgessState.TargetIdWrapper();
            originalWrapper.id        = 1;
            originalWrapper.name      = "Wrapper";
            originalWrapper.nodeId    = 4;
            originalWrapper.projectId = 6;
            waitingBuildStates        = new List <ProjectBuildState>();
            waitingBuildStates.Add(initiatingRequest);

            TargetInProgessState targetInProgress3 = new TargetInProgessState(
                engineCallback,
                build,
                waitingBuildStates,
                initiatingRequest,
                outstandingBuildRequests,
                projectName
                );

            targetInProgress3.ParentTargetsForBuildRequests = new TargetInProgessState.TargetIdWrapper[] { originalWrapper };

            // Stream, writer and reader where the events will be serialized and deserialized from
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);
            BinaryReader reader = new BinaryReader(stream);

            try
            {
                stream.Position = 0;
                // Serialize
                targetInProgress3.WriteToStream(writer);
                // Get position of stream after write so it can be compared to the position after read
                long streamWriteEndPosition = stream.Position;

                // Deserialize and Verify
                stream.Position = 0;
                TargetInProgessState newInProgressState = new TargetInProgessState();
                newInProgressState.CreateFromStream(reader);
                long streamReadEndPosition = stream.Position;
                Assert.IsTrue(string.Compare(newInProgressState.ProjectName, projectName, StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsTrue(string.Compare(newInProgressState.TargetId.name, "t", StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsNotNull(newInProgressState.ParentTargets);
                Assert.IsTrue(newInProgressState.OutstandingBuildRequests.Length == 4);
                Assert.IsNotNull(newInProgressState.ParentBuildRequests);
                Assert.IsNotNull(newInProgressState.ParentTargetsForBuildRequests.Length == 1);

                stream.Position = 0;
                // Serialize
                targetInProgress1.WriteToStream(writer);
                // Get position of stream after write so it can be compared to the position after read
                streamWriteEndPosition = stream.Position;

                // Deserialize and Verify
                stream.Position    = 0;
                newInProgressState = new TargetInProgessState();
                newInProgressState.CreateFromStream(reader);
                streamReadEndPosition = stream.Position;
                Assert.IsTrue(string.Compare(newInProgressState.ProjectName, projectName, StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsTrue(string.Compare(newInProgressState.TargetId.name, "Build", StringComparison.OrdinalIgnoreCase) == 0);
                Assert.IsNotNull(newInProgressState.ParentTargets);
                Assert.IsNull(newInProgressState.OutstandingBuildRequests);
                Assert.IsNotNull(newInProgressState.ParentBuildRequests);

                TargetInProgessState targetInProgress2 = new TargetInProgessState();
                stream.Position = 0;
                // Serialize
                targetInProgress2.WriteToStream(writer);
                // Get position of stream after write so it can be compared to the position after read
                streamWriteEndPosition = stream.Position;

                // Deserialize and Verify
                stream.Position    = 0;
                newInProgressState = new TargetInProgessState();
                newInProgressState.CreateFromStream(reader);
                streamReadEndPosition = stream.Position;
                Assert.IsNull(newInProgressState.ProjectName);
                Assert.IsNull(newInProgressState.TargetId);
                Assert.IsNull(newInProgressState.ParentTargets);
                Assert.IsNull(newInProgressState.OutstandingBuildRequests);
                Assert.IsNull(newInProgressState.ParentBuildRequests);
            }
            finally
            {
                // Close will close the writer/reader and the underlying stream
                writer.Close();
                reader.Close();
                reader = null;
                stream = null;
                writer = null;
            }
        }
コード例 #24
0
ファイル: BuildTask_Tests.cs プロジェクト: 3F/IeXod
        public void SetGetHostObjectInProject()
        {
            string projectContents = @"

                <Project ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>

                    <Target Name=`Build` >
                        <MakeDir Directories=`c:\rajeev` />
                        <Csc Sources=`foo.cs` />
                    </Target>
                
                </Project>
                ";

            Project project = ObjectModelHelpers.CreateInMemoryProject(projectContents);

            MyHostObject hostObject1 = new MyHostObject();
            MyHostObject hostObject2 = new MyHostObject();

            // Set hostObject1 to the "MakeDir" task, and set hostObject2 to the "Csc" task.
            foreach (Target target in project.Targets)
            {
                foreach (BuildTask myTask in target)
                {
                    if (myTask.Name == "MakeDir")
                    {
                        myTask.HostObject = hostObject1;
                    }
                    else if (myTask.Name == "Csc")
                    {
                        myTask.HostObject = hostObject2;
                    }
                    else
                    {
                        Assertion.Assert("Unknown task", false);
                    }
                }
            }

            bool foundMakeDir = false;
            bool foundCsc     = false;

            // Now retrieve the host objects for "MakeDir" and "Csc", and confirm they're the
            // same ones we set originally.
            foreach (Target target in project.Targets)
            {
                foreach (BuildTask myTask in target)
                {
                    if (myTask.Name == "MakeDir")
                    {
                        Assertion.AssertSame(myTask.HostObject, hostObject1);
                        Assertion.Assert(myTask.HostObject != hostObject2);
                        foundMakeDir = true;
                    }
                    else if (myTask.Name == "Csc")
                    {
                        Assertion.AssertSame(myTask.HostObject, hostObject2);
                        Assertion.Assert(myTask.HostObject != hostObject1);
                        foundCsc = true;
                    }
                    else
                    {
                        Assertion.Assert("Unknown task", false);
                    }
                }
            }

            Assertion.Assert(foundMakeDir && foundCsc);
        }
コード例 #25
0
        public void FailingTaskStillPublishesOutputs()
        {
            MockLogger l = new MockLogger();

            string resx = Path.Combine(Path.GetTempPath(), "FailingTaskStillPublishesOutputs.resx");

            try
            {
                File.WriteAllText(resx, @"
                    <root>
                      <resheader name=""resmimetype"">
                        <value>text/microsoft-resx</value>
                      </resheader>
                      <resheader name=""version"">
                        <value>2.0</value>
                      </resheader>
                      <resheader name=""reader"">
                        <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
                      </resheader>
                      <resheader name=""writer"">
                        <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
                      </resheader>
                      <data name=""a"">
                        <value>aa</value>
                      </data>
                      <data name=""b"">
                        <value>bb</value>
                      </data>
                    </root>");

                Project p = ObjectModelHelpers.CreateInMemoryProject(@"
                    <Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> 
                        <Target Name='Build'>
                            
                            <GenerateResource
                                Sources='" + resx + @"'
                                ExecuteAsTool='false'
                                StronglyTypedLanguage='!@:|'>
                                    <Output TaskParameter='FilesWritten' ItemName='FilesWrittenItem'/>
                                    <Output TaskParameter='FilesWritten' PropertyName='FilesWrittenProperty'/>
                            </GenerateResource>
                                               
                            <OnError ExecuteTargets='ErrorTarget'/>
                        </Target>

                        <Target Name='ErrorTarget'>    
                            <Message Text='[@(fileswrittenitem)]'/>
                            <Message Text='[$(fileswrittenproperty)]'/>
                        </Target>
                    </Project>",
                                                                     l
                                                                     );

                p.Build(new string[] { "Build" }, null);

                string resource = Path.ChangeExtension(resx, ".resources");

                Assertion.Assert("Expected one error because 'Build' failed.", l.ErrorCount >= 1);
                l.AssertLogContains("[" + resource + "]", "[" + resource + "]");

                // And outputs are visible at the project level
                Assertion.AssertEquals(resource, p.GetEvaluatedItemsByName("FilesWrittenItem")[0].FinalItemSpec);
                Assertion.AssertEquals(resource, p.GetEvaluatedProperty("FilesWrittenProperty"));

                p.ResetBuildStatus();

                // But are gone after resetting of course
                Assertion.AssertEquals(0, p.GetEvaluatedItemsByName("FilesWrittenItem").Count);
                Assertion.AssertEquals(null, p.GetEvaluatedProperty("FilesWrittenProperty"));
            }
            finally
            {
                File.Delete(resx);
            }
        }
コード例 #26
0
ファイル: Item_Tests.cs プロジェクト: 3F/IeXod
        public void IncludeAndExcludeUnescaping()
        {
            string       tempFolder = Path.Combine(Path.GetTempPath(), "IncludeAndExcludeUnescaping");
            string       matchesFoo = Path.Combine(tempFolder, "*");
            string       foo        = Path.Combine(tempFolder, "foo");
            StreamWriter sw         = null;

            try
            {
                Directory.CreateDirectory(tempFolder);
                sw = File.CreateText(foo);

                string projectContents = String.Format(@"
                    <Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>
                        <ItemGroup>
                            <i1 Include=`)` Exclude=`)`/>
                            <i2 Include=`%29` Exclude=`%29`/>
                            <i3 Include=`%29` Exclude=`)`/>
                            <i4 Include=`)` Exclude=`%29`/>
                            <i5 Include=`);x` Exclude=`%29`/>
                            <i6 Include=`x` Exclude=`y`/>
                            <i7 Include=` ` Exclude=`y`/>
                            <i8 Include=`x` Exclude=``/>
                            <i9 Include=`);%29` Exclude=`)`/>
                            <i10 Include=`%2a` Exclude=`%2a`/>
                            <i11 Include=`{0}` Exclude=`{1}`/>
                            <i12 Include=`{1}` Exclude=`{1}`/>
                        </ItemGroup>
                    </Project>
                    ", foo, matchesFoo);

                Project project = ObjectModelHelpers.CreateInMemoryProject(projectContents);

                BuildItemGroup i1Items  = project.GetEvaluatedItemsByName("i1");
                BuildItemGroup i2Items  = project.GetEvaluatedItemsByName("i2");
                BuildItemGroup i3Items  = project.GetEvaluatedItemsByName("i3");
                BuildItemGroup i4Items  = project.GetEvaluatedItemsByName("i4");
                BuildItemGroup i5Items  = project.GetEvaluatedItemsByName("i5");
                BuildItemGroup i6Items  = project.GetEvaluatedItemsByName("i6");
                BuildItemGroup i7Items  = project.GetEvaluatedItemsByName("i7");
                BuildItemGroup i8Items  = project.GetEvaluatedItemsByName("i8");
                BuildItemGroup i9Items  = project.GetEvaluatedItemsByName("i9");
                BuildItemGroup i10Items = project.GetEvaluatedItemsByName("i10");
                BuildItemGroup i11Items = project.GetEvaluatedItemsByName("i11");
                BuildItemGroup i12Items = project.GetEvaluatedItemsByName("i12");
                Assertion.Assert(") should exclude )", i1Items.Count == 0);
                Assertion.Assert("%29 should exclude %29", i2Items.Count == 0);
                Assertion.Assert(") should exclude %29", i3Items.Count == 0);
                Assertion.Assert("%29 should exclude )", i4Items.Count == 0);
                Assertion.Assert("%29 should exclude ) from );x", i5Items.Count == 1 && i5Items[0].FinalItemSpecEscaped == "x");
                Assertion.Assert("y should not exclude x", i6Items.Count == 1 && i6Items[0].FinalItemSpecEscaped == "x");
                Assertion.Assert("empty include, y exclude", i7Items.Count == 0);
                Assertion.Assert("x include, empty exclude", i8Items.Count == 1 && i8Items[0].FinalItemSpecEscaped == "x");
                Assertion.Assert(") should exclude both from );%29", i9Items.Count == 0);
                Assertion.Assert("%2a should exclude %2a", i10Items.Count == 0);
                Assertion.Assert("* matching foo should exclude foo", i11Items.Count == 0);
                Assertion.Assert("* should exclude *", i12Items.Count == 0);
            }
            finally
            {
                if (null != sw)
                {
                    sw.Close();
                }
                File.Delete(foo);
                Directory.Delete(tempFolder);
            }
        }