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


C# Project.RemoveItem方法代码示例

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


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

示例1: Execute

		public override bool Execute() {
			if (this.ProjectReferences.Length != this.References.Length) {
				this.Log.LogError("ProjectReferences and References arrays do not have matching lengths.");
			}

			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec);

				var projectReferences = doc.EvaluatedItems.OfType<BuildItem>().Where(item => item.Name == "ProjectReference");
				var matchingReferences = from reference in projectReferences
										 join refToRemove in this.ProjectReferences on reference.Include equals refToRemove.ItemSpec
										 let addIndex = Array.IndexOf(this.ProjectReferences, refToRemove)
										 select new { Remove = reference, Add = this.References[addIndex] };
				foreach (var matchingReference in matchingReferences) {
					this.Log.LogMessage("Removing project reference to \"{0}\" from \"{1}\".", matchingReference.Remove.Include, project.ItemSpec);
					doc.RemoveItem(matchingReference.Remove);
					if (matchingReference.Add.ItemSpec != "REMOVE") {
						this.Log.LogMessage("Adding assembly reference to \"{0}\" to \"{1}\".", matchingReference.Add.ItemSpec, project.ItemSpec);
						var newReference = doc.AddNewItem("Reference", Path.GetFileNameWithoutExtension(matchingReference.Add.ItemSpec), true);
						newReference.SetMetadata("HintPath", matchingReference.Add.ItemSpec);
					}
				}

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:jongalloway,项目名称:dotnetopenid,代码行数:29,代码来源:ChangeProjectReferenceToAssemblyReference.cs

示例2: Execute

		public override bool Execute() {
			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec);
				
				var projectReference = doc.EvaluatedItems.OfType<BuildItem>().Where(
					item => item.Name == "ProjectReference" && item.Include == ProjectReference).Single();
				doc.RemoveItem(projectReference);

				var newReference = doc.AddNewItem("Reference", Path.GetFileNameWithoutExtension(Reference));
				newReference.SetMetadata("HintPath", Reference);

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:Belxjander,项目名称:Asuna,代码行数:17,代码来源:ChangeProjectReferenceToAssemblyReference.cs

示例3: Execute

		public override bool Execute() {
			if (this.ProjectReferences.Length != this.References.Length) {
				this.Log.LogError("ProjectReferences and References arrays do not have matching lengths.");
				this.Log.LogError("ProjectReferences contents ({0} elements): {1}", this.ProjectReferences.Length, String.Join<ITaskItem>(";", this.ProjectReferences));
				this.Log.LogError("References contents ({0} elements): {1}", this.References.Length, String.Join<ITaskItem>(";", this.References));
				return false;
			}

			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec, ProjectLoadSettings.IgnoreMissingImports);

				var projectReferences = doc.EvaluatedItems.OfType<BuildItem>().Where(item => item.Name == "ProjectReference");
				var matchingReferences = from reference in projectReferences
										 join refToRemove in this.ProjectReferences on reference.Include equals refToRemove.ItemSpec
										 let addIndex = Array.IndexOf(this.ProjectReferences, refToRemove)
										 select new { Remove = reference, Add = this.References[addIndex] };
				foreach (var matchingReference in matchingReferences) {
					this.Log.LogMessage("Removing project reference to \"{0}\" from \"{1}\".", matchingReference.Remove.Include, project.ItemSpec);
					doc.RemoveItem(matchingReference.Remove);
					if (matchingReference.Add.ItemSpec != "REMOVE") {
						this.Log.LogMessage("Adding assembly reference to \"{0}\" to \"{1}\".", matchingReference.Add.ItemSpec, project.ItemSpec);

						string newItemSpec = Path.GetFileNameWithoutExtension(matchingReference.Add.ItemSpec);
						if (!doc.GetEvaluatedItemsByName("Reference").OfType<BuildItem>().Any(bi => String.Equals(bi.Include, newItemSpec, StringComparison.OrdinalIgnoreCase))) {
							var newReference = doc.AddNewItem("Reference", newItemSpec, true);
							newReference.SetMetadata("HintPath", matchingReference.Add.ItemSpec);
						}
					}
				}

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:36,代码来源:ChangeProjectReferenceToAssemblyReference.cs

示例4: RemoveEvaluatedItemSuccess

 public void RemoveEvaluatedItemSuccess()
 {
     try
     {
         string includePath = Path.Combine(ObjectModelHelpers.TempProjectDir, "*.foo");
         List<string> files = CompatibilityTestHelpers.CreateFiles(4, "foo", "foo", ObjectModelHelpers.TempProjectDir);
         Project p = new Project(new Engine());
         BuildItemGroup group = p.AddNewItemGroup();
         group.AddNewItem("foos", includePath);
         object o = p.EvaluatedItems;
         files.RemoveAt(files.IndexOf(p.EvaluatedItems[0].FinalItemSpec));
         p.RemoveItem(p.EvaluatedItems[0]);
         int i = 0;
         foreach (string fileName in files)
         {
             Assertion.AssertEquals(includePath, group[0].FinalItemSpec);
             Assertion.AssertEquals(includePath, group[0].Include);
             Assertion.AssertEquals(fileName, p.EvaluatedItems[i].Include);
             Assertion.AssertEquals(fileName, p.EvaluatedItems[i].FinalItemSpec);
             i++;
         }
     }
     finally
     {
         CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:27,代码来源:BuildItemGroup_Tests.cs

示例5: RemoveItemLastInGroup

 public void RemoveItemLastInGroup()
 {    
     Project p = new Project();
     BuildItem buildItem = p.AddNewItem("n", "i");
     Assertion.AssertEquals(1, p.ItemGroups.Count);
     p.RemoveItem(buildItem);
     Assertion.AssertEquals(0, p.ItemGroups.Count);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:8,代码来源:Project_Tests.cs

示例6: RemoveItemDirtyAfterRemove

 public void RemoveItemDirtyAfterRemove()
 {
     string projectPath  = ObjectModelHelpers.CreateFileInTempProjectDirectory("save.proj", String.Empty);
     try
     {
         Project p = new Project();
         BuildItem buildItem = p.AddNewItem("n", "i");
         p.Save(projectPath);
         Assertion.AssertEquals(false, p.IsDirty);
         p.RemoveItem(buildItem);
         Assertion.AssertEquals(true, p.IsDirty);
     }
     finally
     {
         CompatibilityTestHelpers.RemoveFile(projectPath);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:17,代码来源:Project_Tests.cs

示例7: RemoveItem_IsNotImported

 public void RemoveItem_IsNotImported()
 {
     Project p = new Project();
     Project i = new Project(p.ParentEngine);
     BuildItem buildItem = i.AddNewItem("n", "i");
     p.RemoveItem(buildItem);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:7,代码来源:Project_Tests.cs

示例8: RemoveItem_IsNotRelatedToProject

 public void RemoveItem_IsNotRelatedToProject()
 {
     Project p = new Project();
     BuildItem buildItem = new BuildItem("n", "i");
     p.RemoveItem(buildItem);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:6,代码来源:Project_Tests.cs

示例9: RemoveItem_null

 public void RemoveItem_null()
 {
     Project p = new Project();
     p.AddNewItem("n", "i", true);
     BuildItem buildItem1 = null;
     p.RemoveItem(buildItem1);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:7,代码来源:Project_Tests.cs

示例10: RemoveItem

 public void RemoveItem()
 {
     Project p = new Project();
     BuildItem buildItem1 = p.AddNewItem("n", "i", true);
     Assertion.AssertNotNull(CompatibilityTestHelpers.FindBuildItem(p, "n"));
     p.RemoveItem(buildItem1);
     Assertion.AssertNull(CompatibilityTestHelpers.FindBuildItem(p, "n"));
 }
开发者ID:nikson,项目名称:msbuild,代码行数:8,代码来源:Project_Tests.cs

示例11: RemoveEvaluatedItemAfterExpansionSuccess

 public void RemoveEvaluatedItemAfterExpansionSuccess()
 {
     try
     {
         int numberOfFoos = 5;
         CompatibilityTestHelpers.CreateFiles(numberOfFoos, "foo", "foo", ObjectModelHelpers.TempProjectDir);
         CompatibilityTestHelpers.CreateFiles(1, "bar", "bar", ObjectModelHelpers.TempProjectDir);
         Project p = new Project();
         p.AddNewItem("foos", Path.Combine(ObjectModelHelpers.TempProjectDir, "*.foo"));
         p.RemoveItem(p.EvaluatedItems[0]);
         Assertion.AssertEquals(true, p.EvaluatedItems[0].Include.Contains("foo1.foo"));
         Assertion.AssertEquals(numberOfFoos - 1, p.EvaluatedItems.Count);
     }
     finally
     {
         CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:18,代码来源:Project_Tests.cs

示例12: RemoveEvaluatedItemDelimitedSuccess

 public void RemoveEvaluatedItemDelimitedSuccess()
 {
     try
     {
         CompatibilityTestHelpers.CreateFiles(1, "foo", "foo", ObjectModelHelpers.TempProjectDir);
         Project p = new Project();
         p.AddNewItem("foos", Path.Combine(ObjectModelHelpers.TempProjectDir, "foo.foo,bar.bar"));
         p.RemoveItem(p.EvaluatedItems[0]);
         Assertion.AssertEquals(0, p.EvaluatedItems.Count);
     }
     finally
     {
         CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:15,代码来源:Project_Tests.cs

示例13: RemoveEvaluatedItemDelimtedFails

 public void RemoveEvaluatedItemDelimtedFails()
 {
     try
     {
         CompatibilityTestHelpers.CreateFiles(1, "foo", "foo", ObjectModelHelpers.TempProjectDir);
         Project p = new Project();
         object o = p.EvaluatedItems; // this causes the failure
         p.AddNewItem("foos", Path.Combine(ObjectModelHelpers.TempProjectDir, "foo.foo;bar.bar"));
         p.RemoveItem(p.EvaluatedItems[0]); // Exception thrown here
         Assertion.Fail("success as failure"); // should not get here due to exception above
     }
     catch (Exception e)
     {
         if (!(e.GetType().ToString().Contains("InternalErrorException")))
         {
              Assertion.Fail(e.Message + " was thrown");
         }
         else
         {
             Assertion.Assert("InternalErrorException was thrown", true);
         }
     }
     finally
     {
         CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:27,代码来源:Project_Tests.cs

示例14: RemoveEvaluatedItemAfterExpansionFails

 public void RemoveEvaluatedItemAfterExpansionFails()
 {
     try
     {
         CompatibilityTestHelpers.CreateFiles(2, "foo", "foo", ObjectModelHelpers.TempProjectDir);
         Project p = new Project();
         object o = p.EvaluatedItems; // this causes failure
         p.AddNewItem("foos", Path.Combine(ObjectModelHelpers.TempProjectDir, "*.foo"));
         p.RemoveItem(p.EvaluatedItems[0]);   // Exception thrown here
         Assertion.Fail("success as failure"); // should not get here due to exception above
     }
     catch (Exception e)
     {
         // ExpectedException cannot be asserted as InternalErrorExceptions are internally scoped.
         Assertion.AssertEquals(true, e.GetType().ToString().Contains("InternalErrorException"));
     }
     finally
     {
         CompatibilityTestHelpers.CleanupDirectory(ObjectModelHelpers.TempProjectDir);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:21,代码来源:Project_Tests.cs


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