本文整理汇总了C#中Microsoft.Build.Evaluation.Project.RemoveItems方法的典型用法代码示例。如果您正苦于以下问题:C# Project.RemoveItems方法的具体用法?C# Project.RemoveItems怎么用?C# Project.RemoveItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Evaluation.Project
的用法示例。
在下文中一共展示了Project.RemoveItems方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cleanup
private static void Cleanup(Project project, string itemTypeToCleanup)
{
var items = project.Items.Where(x => x.ItemType == itemTypeToCleanup).ToList();
project.RemoveItems(items);
var sortedItems = items.OrderBy(x => x.UnevaluatedInclude);
foreach (var item in sortedItems)
project.AddItemFast(itemTypeToCleanup, item.UnevaluatedInclude);
}
示例2: TestRunPythonCommand
public void TestRunPythonCommand() {
var expectedSearchPath = string.Format("['{0}', '{1}']",
TestData.GetPath(@"TestData").Replace("\\", "\\\\"),
TestData.GetPath(@"TestData\HelloWorld").Replace("\\", "\\\\")
);
var proj = new Project(TestData.GetPath(@"TestData\Targets\Commands4.pyproj"));
foreach (var version in PythonPaths.Versions) {
var verStr = version.Version.ToVersion().ToString();
proj.SetProperty("InterpreterId", version.Id.ToString("B"));
proj.SetProperty("InterpreterVersion", verStr);
proj.RemoveItems(proj.ItemsIgnoringCondition.Where(i => i.ItemType == "InterpreterReference").ToArray());
proj.AddItem("InterpreterReference", string.Format("{0:B}\\{1}", version.Id, verStr));
proj.Save();
proj.ReevaluateIfNecessary();
var log = new StringLogger(LoggerVerbosity.Minimal);
Assert.IsTrue(proj.Build("CheckCode", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed), log }));
Console.WriteLine();
Console.WriteLine("Output from {0:B} {1}", version.Id, version.Version.ToVersion());
foreach (var line in log.Lines) {
Console.WriteLine("* {0}", line.TrimEnd('\r', '\n'));
}
var logLines = log.Lines.Last().Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
Assert.AreEqual(2, logLines.Length);
Assert.AreEqual(version.Version.ToVersion().ToString(), logLines[0].Trim());
Assert.AreEqual(expectedSearchPath, logLines[1].Trim());
}
}
示例3: RemoveZombiedItem
public void RemoveZombiedItem()
{
string projectOriginalContents = ObjectModelHelpers.CleanupFileContents(@"
<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
<i Include='i1' />
</ItemGroup>
</Project>
");
Project project = new Project(XmlReader.Create(new StringReader(projectOriginalContents)));
ProjectItem item = project.GetItems("i").FirstOrDefault();
project.RemoveItems(new List<ProjectItem>() { item });
project.RemoveItems(new List<ProjectItem>() { item });
Assert.Equal(0, project.Items.Count());
}
示例4: RemoveItemWrongProject
public void RemoveItemWrongProject()
{
Assert.Throws<ArgumentException>(() =>
{
ProjectRootElement root1 = ProjectRootElement.Create();
root1.AddItem("i", "i1");
ProjectRootElement root2 = ProjectRootElement.Create();
root2.AddItem("i", "i1");
Project project1 = new Project(root1);
Project project2 = new Project(root2);
project1.RemoveItems(project2.Items);
}
);
}
示例5: RemoveItemsOneNull
public void RemoveItemsOneNull()
{
Assert.Throws<ArgumentNullException>(() =>
{
Project project = new Project();
project.RemoveItems(new List<ProjectItem>() { null });
}
);
}
示例6: RemoveSeveralItemsExpandExpression
public void RemoveSeveralItemsExpandExpression()
{
string projectOriginalContents = ObjectModelHelpers.CleanupFileContents(@"
<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
<i Include='i1;i2' />
<j Include='@(i);j2' />
</ItemGroup>
</Project>
");
Project project = new Project(XmlReader.Create(new StringReader(projectOriginalContents)));
project.RemoveItems(project.GetItems("j").Take(2));
Assert.Equal(3, project.Items.Count());
StringWriter writer = new StringWriter();
project.Save(writer);
string projectExpectedContents = ObjectModelHelpers.CleanupFileContents(@"
<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
<i Include='i1;i2' />
<j Include='j2' />
</ItemGroup>
</Project>
");
Helpers.CompareProjectXml(projectExpectedContents, writer.ToString());
}
示例7: RemoveSeveralItemsOfVariousTypes
public void RemoveSeveralItemsOfVariousTypes()
{
string projectOriginalContents = ObjectModelHelpers.CleanupFileContents(@"
<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
<i Include='i1' />
<j Include='j1' />
<j Include='j2' />
<k Include='k1' />
</ItemGroup>
</Project>
");
Project project = new Project(XmlReader.Create(new StringReader(projectOriginalContents)));
List<ProjectItem> list = new List<ProjectItem>() { project.GetItems("i").FirstOrDefault(), project.GetItems("j").FirstOrDefault() };
project.RemoveItems(list);
Assert.Equal(2, project.Items.Count());
}
示例8: RemoveItemWrongProject
public void RemoveItemWrongProject()
{
ProjectRootElement root1 = ProjectRootElement.Create();
root1.AddItem("i", "i1");
ProjectRootElement root2 = ProjectRootElement.Create();
root2.AddItem("i", "i1");
Project project1 = new Project(root1);
Project project2 = new Project(root2);
project1.RemoveItems(project2.Items);
}
示例9: RemoveItemsOneNull
public void RemoveItemsOneNull()
{
Project project = new Project();
project.RemoveItems(new List<ProjectItem>() { null });
}
示例10: RemoveSeveralItemsFirstZombiesSecond
public void RemoveSeveralItemsFirstZombiesSecond()
{
string projectOriginalContents = ObjectModelHelpers.CleanupFileContents(@"
<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
<i Include='i1;i2' />
</ItemGroup>
</Project>
");
Project project = new Project(XmlReader.Create(new StringReader(projectOriginalContents)));
project.RemoveItems(project.GetItems("i"));
Assert.AreEqual(0, project.Items.Count());
}
示例11: FixReferences
private void FixReferences(Project project, Dictionary<ProjectItem, ReferenceConfig> referencesToRemove)
{
foreach (var referenceConfig in referencesToRemove.Values)
{
_processedReferences[referenceConfig] = true;
}
project.RemoveItems(referencesToRemove.Keys);
foreach (var referenceToRemove in referencesToRemove.Values)
{
project.AddItem(ProjectStrings.AssemblyReference, referenceToRemove.AssemblyReference,
referenceToRemove.CreateMetaData(project.FullPath));
}
}
示例12: ExcludePaths
private static void ExcludePaths(Project proj, IReadOnlyList<string> excludedPaths)
{
var toRemove = proj.Items.Where(item => excludedPaths.Contains(item.UnevaluatedInclude)).ToList();
proj.RemoveItems(toRemove);
}
示例13: RemoveCheckingFromCsproj
public static void RemoveCheckingFromCsproj(Project proj)
{
var toRemove = proj.Items.Where(IsChecking).ToList();
proj.RemoveItems(toRemove);
}