public static ProjectRootElement ShallowCloneWithoutSdkOrXmlnsAttribute(this ProjectRootElement originalRoot)
        {
            ProjectRootElement newRoot = ProjectRootElement.Create(NewProjectFileOptions.None);

            foreach (ProjectElement projectElement in originalRoot.Children)
            {
                if (projectElement is ProjectImportGroupElement importGroup)
                {
                    ProjectImportGroupElement newImportGroup = newRoot.CreateImportGroupElement();
                    foreach (ProjectImportElement import in importGroup.Imports)
                    {
                    }
                }
            }
            if (!string.IsNullOrEmpty(originalRoot.DefaultTargets))
            {
                newRoot.DefaultTargets = originalRoot.DefaultTargets;
            }
            if (!string.IsNullOrEmpty(originalRoot.TreatAsLocalProperty))
            {
                newRoot.TreatAsLocalProperty = originalRoot.TreatAsLocalProperty;
            }
            if (!string.IsNullOrEmpty(originalRoot.ToolsVersion))
            {
                newRoot.ToolsVersion = originalRoot.ToolsVersion;
            }
            return(newRoot);
        }
Ejemplo n.º 2
0
        public static void Verify(ProjectImportGroupElement viewXml, ProjectImportGroupElement realXml, ValidationContext context = null)
        {
            if (viewXml == null && realXml == null)
            {
                return;
            }
            VerifyProjectElement(viewXml, realXml, context);

            ViewValidation.Verify(viewXml.Imports, realXml.Imports, ViewValidation.Verify, context);
        }
        public void SetLabel()
        {
            ProjectRootElement project = ProjectRootElement.Create();

            project.AddImportGroup();
            Helpers.ClearDirtyFlag(project);

            ProjectImportGroupElement importGroup = Helpers.GetFirst(project.ImportGroups);

            importGroup.Label = "c";

            Assert.Equal("c", importGroup.Label);
            Assert.True(project.HasUnsavedChanges);
        }
Ejemplo n.º 4
0
        public void SetCondition()
        {
            ProjectRootElement project = ProjectRootElement.Create();

            project.AddImportGroup();
            Helpers.ClearDirtyFlag(project);

            ProjectImportGroupElement importGroup = Helpers.GetFirst(project.ImportGroups);

            importGroup.Condition = "c";

            Assert.AreEqual("c", importGroup.Condition);
            Assert.AreEqual(true, project.HasUnsavedChanges);
        }
        public void ReadNoChild()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <ImportGroup />
                    </Project>
                ";

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

            ProjectImportGroupElement importGroup = (ProjectImportGroupElement)Helpers.GetFirst(project.ImportGroups);

            Assert.Null(project.Imports.GetEnumerator().Current);
            Assert.Equal(0, Helpers.Count(importGroup.Imports));
        }
        public void ReadNoChild()
        {
            string content = @"
                    <Project>
                        <ImportGroup />
                    </Project>
                ";

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

            ProjectImportGroupElement importGroup = (ProjectImportGroupElement)Helpers.GetFirst(project.ImportGroups);

            Assert.Null(project.Imports.GetEnumerator().Current);
            Assert.Equal(0, Helpers.Count(importGroup.Imports));
        }
Ejemplo n.º 7
0
        public void SetProjectInvalidEmpty()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <ImportGroup>
                            <Import Project='i1.proj' />
                        </ImportGroup>
                    </Project>
                ";

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

            ProjectImportGroupElement importGroup = (ProjectImportGroupElement)Helpers.GetFirst(project.Children);

            ProjectImportElement import = (ProjectImportElement)Helpers.GetFirst(importGroup.Imports);

            import.Project = String.Empty;
        }
        public void SetProjectValid()
        {
            string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <ImportGroup>
                            <Import Project='i1.proj' />
                        </ImportGroup>
                    </Project>
                ";

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

            ProjectImportGroupElement importGroup = (ProjectImportGroupElement)Helpers.GetFirst(project.Children);

            ProjectImportElement import = (ProjectImportElement)Helpers.GetFirst(importGroup.Imports);

            import.Project = "i1b.proj";
            Assert.Equal("i1b.proj", import.Project);
            Assert.True(project.HasUnsavedChanges);
        }
        public void SetProjectValid()
        {
            string content = @"
                    <Project>
                        <ImportGroup>
                            <Import Project='i1.proj' />
                        </ImportGroup>
                    </Project>
                ";

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

            ProjectImportGroupElement importGroup = (ProjectImportGroupElement)Helpers.GetFirst(project.Children);

            ProjectImportElement import = (ProjectImportElement)Helpers.GetFirst(importGroup.Imports);

            import.Project = "i1b.proj";
            Assert.Equal("i1b.proj", import.Project);
            Assert.True(project.HasUnsavedChanges);
        }
        public void SetProjectInvalidEmpty()
        {
            Assert.Throws <ArgumentException>(() =>
            {
                string content = @"
                    <Project>
                        <ImportGroup>
                            <Import Project='i1.proj' />
                        </ImportGroup>
                    </Project>
                ";

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

                ProjectImportGroupElement importGroup = (ProjectImportGroupElement)Helpers.GetFirst(project.Children);

                ProjectImportElement import = (ProjectImportElement)Helpers.GetFirst(importGroup.Imports);

                import.Project = String.Empty;
            }
                                              );
        }
Ejemplo n.º 11
0
        public void ImportGroupDoubleChildPlusCondition()
        {
            ProjectRootElement xml1 = ProjectRootElement.Create("p1");

            xml1.AddProperty("p", "v1");
            ProjectImportGroupElement group = xml1.AddImportGroup();

            group.Condition = "true";
            group.AddImport("p2");
            group.AddImport("p3");
            ProjectRootElement xml2 = ProjectRootElement.Create("p2");

            xml2.AddProperty("p", "v2");
            ProjectRootElement xml3 = ProjectRootElement.Create("p3");

            xml3.AddProperty("p", "v3");

            Project project = new Project(xml1);

            StringWriter writer = new StringWriter();

            project.SaveLogicalProject(writer);

            string expected = ObjectModelHelpers.CleanupFileContents(
                @"<?xml version=""1.0"" encoding=""utf-16""?>
<!--
============================================================================================================================================
" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p1
============================================================================================================================================
-->
<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <PropertyGroup>
    <p>v1</p>
  </PropertyGroup>
  <!--<ImportGroup Condition=""true"">-->
  <!--
============================================================================================================================================
  <Import Project=""p2"">

" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p2
============================================================================================================================================
-->
  <PropertyGroup>
    <p>v2</p>
  </PropertyGroup>
  <!--
============================================================================================================================================
  </Import>

" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p1
============================================================================================================================================
-->
  <!--
============================================================================================================================================
  <Import Project=""p3"">

" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p3
============================================================================================================================================
-->
  <PropertyGroup>
    <p>v3</p>
  </PropertyGroup>
  <!--
============================================================================================================================================
  </Import>

" + CurrentDirectoryXmlCommentFriendly + Path.DirectorySeparatorChar + @"p1
============================================================================================================================================
-->
  <!--</ImportGroup>-->
</Project>");

            Helpers.VerifyAssertLineByLine(expected, writer.ToString());
        }