本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例8: RemoveItem_IsNotRelatedToProject
public void RemoveItem_IsNotRelatedToProject()
{
Project p = new Project();
BuildItem buildItem = new BuildItem("n", "i");
p.RemoveItem(buildItem);
}
示例9: RemoveItem_null
public void RemoveItem_null()
{
Project p = new Project();
p.AddNewItem("n", "i", true);
BuildItem buildItem1 = null;
p.RemoveItem(buildItem1);
}
示例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"));
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}