本文整理汇总了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)});
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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")) });
}