当前位置: 首页>>代码示例>>C#>>正文


C# Project.RemoveItem方法代码示例

本文整理汇总了C#中Microsoft.Build.Evaluation.Project.RemoveItem方法的典型用法代码示例。如果您正苦于以下问题:C# Project.RemoveItem方法的具体用法?C# Project.RemoveItem怎么用?C# Project.RemoveItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Build.Evaluation.Project的用法示例。


在下文中一共展示了Project.RemoveItem方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LinkToFile

        public void LinkToFile(Project project, BuildAction buildAction, string includeValue, string projectTargetPath)
        {
            if(projectTargetPath.StartsWith("\\"))
                throw new Exception("project target path cannot begin with a backslash");

            var matchingProjectItemByTargetPath = (from t in project.Items
                                                   where
                                                       t.HasMetadata("Link") &&
                                                       t.GetMetadataValue("Link") == projectTargetPath
                                                   select t).SingleOrDefault();

            if (matchingProjectItemByTargetPath != null) 
                project.RemoveItem(matchingProjectItemByTargetPath);

            var buildActionName = Enum.GetName(typeof(BuildAction), buildAction);

            project.AddItem(buildActionName, includeValue,
                            new[] {new KeyValuePair<string, string>("Link", projectTargetPath)});
        }
开发者ID:GeniusCode,项目名称:GeniusCode.Toolkit.ProjectAutoFileLinker,代码行数:19,代码来源:ProjectFileLinker.cs

示例2: RemoveItemOutdatedByUpdate

        public void RemoveItemOutdatedByUpdate()
        {
            string projectOriginalContents = ObjectModelHelpers.CleanupFileContents(@"
                <Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
                    <ItemGroup>
                        <Compile Include='a.cs' />
                    </ItemGroup>
                </Project>
                ");
            Project project = new Project(XmlReader.Create(new StringReader(projectOriginalContents)));
            ProjectItem itemToRemove = Helpers.GetFirst(project.GetItems("Compile"));
            itemToRemove.UnevaluatedInclude = "b.cs";
            project.RemoveItem(itemToRemove); // should not throw

            Assert.Equal(0, Helpers.MakeList(project.Items).Count);
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:16,代码来源:Project_Tests.cs

示例3: ItemsByEvaluatedIncludeDirectRemove

        public void ItemsByEvaluatedIncludeDirectRemove()
        {
            Project project = new Project();
            ProjectItem item1 = project.AddItem("i", "i1;j1")[0];
            project.RemoveItem(item1);

            List<ProjectItem> items = Helpers.MakeList(project.GetItemsByEvaluatedInclude("i1"));
            Assert.Equal(0, items.Count);
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:9,代码来源:Project_Tests.cs

示例4: ItemsByEvaluatedIncludeAndExpansion

        public void ItemsByEvaluatedIncludeAndExpansion()
        {
            List<string> filePaths = new List<string>();
            string testFileRoot = null;
            try
            {
                int count = 0;
                testFileRoot = Path.Combine(Path.GetTempPath(), "foodir");
                Directory.CreateDirectory(testFileRoot);
                int maxFiles = 2;
                for (int i = 0; i < maxFiles; i++)
                {
                    string fileName = String.Format("foo{0}.foo", i);
                    string filePath = Path.Combine(testFileRoot, fileName);
                    File.WriteAllText(filePath, String.Empty);
                    filePaths.Add(filePath);
                }

                ProjectRootElement projectConstruction = ProjectRootElement.Create();
                projectConstruction.AddItem("foo", Path.Combine(testFileRoot, "*.foo"));

                count = Helpers.Count(projectConstruction.Items);
                Assert.Equal(1, count); // "Construction Model"

                Project project = new Project(projectConstruction);

                count = Helpers.Count(project.GetItems("foo"));
                Assert.Equal(2, count); // "Evaluation Model, Before Removal"

                ProjectItem itemToRemove = null;

                // Get the first item from IEnumerable Collection.
                foreach (ProjectItem item in project.Items)
                {
                    itemToRemove = item;
                    break;
                }

                project.RemoveItem(itemToRemove);
                count = Helpers.Count(project.GetItems("foo"));
                Assert.Equal(1, count); // "Evaluation Model, After Removal"

                ProjectInstance projectInstance = project.CreateProjectInstance();
                count = Helpers.Count(projectInstance.Items);
                Assert.Equal(1, count); // "Instance Model"

                // Ensure XML has been updated accordingly on the Evaluation model (projectInstance doesn't back onto XML)
                Assert.False(project.Xml.RawXml.Contains(itemToRemove.Xml.Include));
                Assert.False(project.Xml.RawXml.Contains("*.foo"));
            }
            finally
            {
                foreach (string filePathToRemove in filePaths)
                {
                    File.Delete(filePathToRemove);
                }

                Directory.Delete(testFileRoot);
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:60,代码来源:Project_Tests.cs

示例5: RemoveItem_IncludingFromIgnoringConditionList

        public void RemoveItem_IncludingFromIgnoringConditionList()
        {
            XmlReader content = XmlReader.Create(new StringReader(ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <ItemGroup Condition=""false"">
    <i Include=""i1"" />
  </ItemGroup>
</Project>")));

            Project project = new Project(content);

            Assert.Equal(0, Helpers.MakeList(project.GetItems("i")).Count);
            List<ProjectItem> itemsIgnoringCondition = Helpers.MakeList(project.GetItemsIgnoringCondition("i"));
            Assert.Equal(1, itemsIgnoringCondition.Count);
            ProjectItem item = itemsIgnoringCondition[0];
            Assert.Equal("i1", item.EvaluatedInclude);

            bool result = project.RemoveItem(item);

            Assert.Equal(false, result); // false as it was not in the regular items collection
            itemsIgnoringCondition = Helpers.MakeList(project.GetItemsIgnoringCondition("i"));
            Assert.Equal(0, itemsIgnoringCondition.Count);
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:23,代码来源:DefinitionEditing_Tests.cs

示例6: RemoveItem_OriginatingWithWildcard

        public void RemoveItem_OriginatingWithWildcard()
        {
            string[] paths = null;

            try
            {
                paths = Helpers.CreateFiles("i1.xxx", "i2.xxx");
                string directory = Path.GetDirectoryName(paths[0]);
                string wildcard = Path.Combine(directory, "*.xxx;");

                Project project = new Project();
                ProjectItemElement itemElement = project.Xml.AddItem("i", wildcard);
                itemElement.AddMetadata("m", "m1");
                project.ReevaluateIfNecessary();

                ProjectItem item = Helpers.GetFirst(project.Items);
                project.RemoveItem(item);

                string expected = String.Format(
                    ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <ItemGroup>
    <i Include=""{0}"">
      <m>m1</m>
    </i>
  </ItemGroup>
</Project>"
            ),
                    Path.Combine(directory, "i2.xxx"));

                Helpers.VerifyAssertProjectContent(expected, project.Xml);
            }
            finally
            {
                Helpers.DeleteFiles(paths);
            }
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:37,代码来源:DefinitionEditing_Tests.cs

示例7: RemoveItem_OriginatingWithSemicolon

        public void RemoveItem_OriginatingWithSemicolon()
        {
            Project project = new Project();
            project.Xml.AddItem("i", "i1;i2");
            project.ReevaluateIfNecessary();

            project.RemoveItem(Helpers.GetFirst(project.GetItems("i")));

            string expected = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <ItemGroup>
    <i Include=""i2"" />
  </ItemGroup>
</Project>");

            Helpers.VerifyAssertProjectContent(expected, project.Xml);
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:17,代码来源:DefinitionEditing_Tests.cs

示例8: RemoveItem_OriginatingWithItemList

        public void RemoveItem_OriginatingWithItemList()
        {
            XmlReader content = XmlReader.Create(new StringReader(ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <ItemGroup>
    <h Include=""h1;h2"">
      <m>m1</m>
    </h>
    <i Include=""@(h)"" />
  </ItemGroup>
</Project>")));

            Project project = new Project(content);

            project.RemoveItem(Helpers.GetFirst(project.GetItems("i")));

            string expected = ObjectModelHelpers.CleanupFileContents(
@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"">
  <ItemGroup>
    <h Include=""h1;h2"">
      <m>m1</m>
    </h>
    <i Include=""h2"">
      <m>m1</m>
    </i>
  </ItemGroup>
</Project>");

            Helpers.VerifyAssertProjectContent(expected, project.Xml, false);
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:30,代码来源:DefinitionEditing_Tests.cs

示例9: RemoveItem

        public void RemoveItem()
        {
            Project project = new Project();
            project.AddItem("i", "i1");
            project.ReevaluateIfNecessary();

            project.RemoveItem(Helpers.GetFirst(project.GetItems("i")));

            string expected = ObjectModelHelpers.CleanupFileContents(@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"" />");

            Helpers.VerifyAssertProjectContent(expected, project.Xml);

            Assert.Equal(0, Helpers.Count(project.Items));
            Assert.Equal(0, Helpers.MakeList(project.CreateProjectInstance().GetItems("i")).Count);
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:15,代码来源:DefinitionEditing_Tests.cs

示例10: ProjectRemoveItemFormatting

        public void ProjectRemoveItemFormatting()
        {
            string content = ObjectModelHelpers.CleanupFileContents(@"
<Project DefaultTargets=`Build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`>
  <ItemGroup>
    <Compile Include=""Class1.cs"" />
    <Compile Include=""Class2.cs""/>
    <Compile Include=""Program.cs""/>
  </ItemGroup>
</Project>");

            ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)),
                ProjectCollection.GlobalProjectCollection,
                preserveFormatting: true);
            Project project = new Project(xml);

            var itemToRemove = project.GetItems("Compile").Single(item => item.EvaluatedInclude == "Class2.cs");
            project.RemoveItem(itemToRemove);
            
            StringWriter writer = new StringWriter();
            project.Save(writer);

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

            string actual = writer.ToString();

            VerifyAssertLineByLine(expected, actual);
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:34,代码来源:ProjectFormatting_Tests.cs

示例11: RemoveProjectReferences

		internal void RemoveProjectReferences()
		{
			var projects = GetProjects();
			var thisProject = projects.FirstOrDefault(c => c.GuidString == "{7AAC4FDB-1C6A-453F-8126-D2E89BC1B6D9}");
			if (thisProject == null)
				throw new Exception("Cannot find Generator Project, operation failed.");
			var gen = new Project(thisProject.AbsolutePath);
			gen.GetItems("ProjectReference").ForEach(
				c => gen.RemoveItem(c)
				);
			gen.Save();
			ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
		}
开发者ID:MiniverCheevy,项目名称:Spawn,代码行数:13,代码来源:VisualStudioHelper.cs

示例12: ReplaceReference

 private static void ReplaceReference(Project project, ProjectItem item, string reference, string path)
 {
     project.RemoveItem(item);
     project.AddItem("Reference", reference, new[] { new KeyValuePair<string, string>("HintPath", Path.Combine(path, reference + ".dll")) });
 }
开发者ID:SymbolSource,项目名称:Orchard,代码行数:5,代码来源:Program.cs


注:本文中的Microsoft.Build.Evaluation.Project.RemoveItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。