コード例 #1
0
        public void SetUnevaluatedValue()
        {
            string content = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace' >
                        <ItemGroup>
                            <i Include='i1'>
                                <m1>v1</m1>
                                <m2>v%253</m2>
                            </i>
                        </ItemGroup>
                    </Project>
                ");

            ProjectRootElement projectXml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            Project project = new Project(projectXml);

            Assert.Equal(false, project.IsDirty);

            Helpers.GetFirst(project.GetItems("i")).SetMetadataValue("m1", "v2");
            Helpers.GetFirst(project.GetItems("i")).SetMetadataValue("m2", "v%214");

            Assert.Equal(true, project.IsDirty);

            StringWriter writer = new EncodingStringWriter();
            projectXml.Save(writer);

            string expected = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace' >
                        <ItemGroup>
                            <i Include='i1'>
                                <m1>v2</m1>
                                <m2>v%214</m2>
                            </i>
                        </ItemGroup>
                    </Project>
                ");

            Helpers.CompareProjectXml(expected, writer.ToString());
            Assert.Equal("v!4", Helpers.GetFirst(project.GetItems("i")).GetMetadataValue("m2"));
        }
コード例 #2
0
ファイル: Project_Tests.cs プロジェクト: cdmihai/msbuild
        public void RemoveSeveralItemsExpandExpression()
        {
            string projectOriginalContents = ObjectModelHelpers.CleanupFileContents(@"
                <Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
                    <ItemGroup>
                        <i Include='i1;i2' />
                        <j Include='@(i);j2' />
                    </ItemGroup>
                </Project>
                ");
            Project project = new Project(XmlReader.Create(new StringReader(projectOriginalContents)));

            project.RemoveItems(project.GetItems("j").Take(2));
            Assert.Equal(3, project.Items.Count());

            StringWriter writer = new EncodingStringWriter();
            project.Save(writer);

            string projectExpectedContents = ObjectModelHelpers.CleanupFileContents(@"
                <Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
                    <ItemGroup>
                        <i Include='i1;i2' />
                        <j Include='j2' />
                    </ItemGroup>
                </Project>
                ");

            Helpers.CompareProjectXml(projectExpectedContents, writer.ToString());
        }
コード例 #3
0
        public void ChangeItemTypeWithXmlHeader()
        {
            string expected = ObjectModelHelpers.CleanupFileContents(@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project>
  <ItemGroup>
    <ProjectReference Include=`..\CLREXE\CLREXE.vcxproj` />
  </ItemGroup>
</Project>");

            Project project = new Project(NewProjectFileOptions.IncludeXmlDeclaration);
            var item = project.AddItem("NotProjectReference", @"..\CLREXE\CLREXE.vcxproj");
            item[0].ItemType = "ProjectReference";

            // Should still output XML declaration even when using UTF8 (NewProjectFileOptions.IncludeXmlDeclaration
            // was specified)
            StringWriter writer = new EncodingStringWriter();
            project.Save(writer);

            string actual = writer.ToString();

            VerifyAssertLineByLine(expected, actual);
        }
コード例 #4
0
        public void ChangeItemTypeNoNamespace()
        {
            string expected = ObjectModelHelpers.CleanupFileContents(@"<Project>
  <ItemGroup>
    <ProjectReference Include=`..\CLREXE\CLREXE.vcxproj` />
  </ItemGroup>
</Project>");

            Project project = new Project(NewProjectFileOptions.None);
            var item = project.AddItem("NotProjectReference", @"..\CLREXE\CLREXE.vcxproj");
            item[0].ItemType = "ProjectReference";

            StringWriter writer = new EncodingStringWriter();
            project.Save(writer);

            string actual = writer.ToString();

            VerifyAssertLineByLine(expected, actual);
        }
コード例 #5
0
        public void NewProjectSaveWithOptionsNone()
        {
            // When NewProjectFileOptions.None is specified, we should not have an XML declaration,
            // tools version, or namespace in the project file.
            string expected = ObjectModelHelpers.CleanupFileContents(@"<Project>
  <ItemGroup>
    <ProjectReference Include=`..\CLREXE\CLREXE.vcxproj`>
      <metadata>value</metadata>
    </ProjectReference>
  </ItemGroup>
</Project>");

            Project project = new Project(NewProjectFileOptions.None);
            var item = project.AddItem("ProjectReference", @"..\CLREXE\CLREXE.vcxproj");
            item[0].SetMetadataValue("metadata", "value");

            StringWriter writer = new EncodingStringWriter();
            project.Save(writer);

            string actual = writer.ToString();

            VerifyAssertLineByLine(expected, actual);
        }
コード例 #6
0
        public void DefaultProjectSaveContainsAllNewFileOptions()
        {
            // XML declaration tag, namespace, and tools version must be present by default.
            string expected = ObjectModelHelpers.CleanupFileContents(@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <ItemGroup>
    <ProjectReference Include=`..\CLREXE\CLREXE.vcxproj`>
      <metadata>value</metadata>
    </ProjectReference>
  </ItemGroup>
</Project>");

            Project project = new Project();
            project.AddItem("ProjectReference", @"..\CLREXE\CLREXE.vcxproj",
                new[] {new KeyValuePair<string, string>("metadata", "value")});
            
            StringWriter writer = new EncodingStringWriter();
            project.Save(writer);

            string actual = writer.ToString();

            VerifyAssertLineByLine(expected, actual);
        }
コード例 #7
0
        public void ProjectAddItemFormatting_EmptyGroup()
        {
            string content = ObjectModelHelpers.CleanupFileContents(@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
  <ItemGroup>
  </ItemGroup>
</Project>");
            ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)),
                ProjectCollection.GlobalProjectCollection,
                preserveFormatting: true);
            Project project = new Project(xml);
            project.AddItem("Compile", "Program.cs");
            StringWriter writer = new EncodingStringWriter();
            project.Save(writer);

            string expected = ObjectModelHelpers.CleanupFileContents(@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
  <ItemGroup>
    <Compile Include=""Program.cs"" />
  </ItemGroup>
</Project>");

            string actual = writer.ToString();

            VerifyAssertLineByLine(expected, actual);
        }