本文整理汇总了C#中Microsoft.Build.BuildEngine.BuildItemGroup类的典型用法代码示例。如果您正苦于以下问题:C# BuildItemGroup类的具体用法?C# BuildItemGroup怎么用?C# BuildItemGroup使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BuildItemGroup类属于Microsoft.Build.BuildEngine命名空间,在下文中一共展示了BuildItemGroup类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestFalseWhen
public void TestFalseWhen () {
Engine engine;
Project project;
BuildItemGroup[] groups = new BuildItemGroup[1];
string documentString = @"
<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Choose>
<When Condition=""'$(Configuration)' == 'False'"">
<ItemGroup>
<A Include='a' />
</ItemGroup>
</When>
</Choose>
</Project>
";
engine = new Engine (Consts.BinPath);
project = engine.CreateNewProject ();
project.LoadXml (documentString);
//Assert.AreEqual (1, project.ItemGroups.Count, "A1");
Assert.AreEqual (0, project.PropertyGroups.Count, "A2");
Assert.AreEqual (0, project.EvaluatedItems.Count, "A3");
Assert.AreEqual (0, project.EvaluatedItemsIgnoringCondition.Count, "A4");
}
示例2: BasicProxying
public void BasicProxying()
{
BuildItemGroup ig = new BuildItemGroup();
BuildItem i1 = new BuildItem("name1", "value1");
i1.SetMetadata("myMetaName", "myMetaValue");
BuildItem i2 = new BuildItem("name2", "value2");
ig.AddItem(i1);
ig.AddItem(i2);
BuildItemGroupProxy proxy = new BuildItemGroupProxy(ig);
// Gather everything into our own table
Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);
foreach (DictionaryEntry item in proxy)
{
list.Add(item.Key, item.Value);
}
// Check we got all the items
Assertion.AssertEquals(2, list.Count);
Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
Assertion.AssertEquals("value2", ((TaskItem)list["name2"]).ItemSpec);
// Check they have all their metadata
int builtInMetadata = FileUtilities.ItemSpecModifiers.All.Length;
Assertion.AssertEquals(1 + builtInMetadata, ((TaskItem)list["name1"]).MetadataCount);
Assertion.AssertEquals(0 + builtInMetadata, ((TaskItem)list["name2"]).MetadataCount);
Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));
}
示例3: BuildItemProxy
internal BuildItemProxy(object buildItem)
{
instance = (Microsoft.Build.BuildEngine.BuildItem)buildItem;
// I am not sure what's going on here, but sometimes, in particular when the project is initialized
// the build item is not what we are getting here, but rather the child element
// 'get_ParentPersistedItem" gives us what we need
var persisted_instance = (BuildItem)typeof(BuildItem)
.InvokeMember("get_ParentPersistedItem", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance, null, instance, new object[] { });
if (persisted_instance != null)
instance = persisted_instance;
buildItemGroup = (BuildItemGroup)typeof(BuildItem)
.InvokeMember("get_ParentPersistedItemGroup", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Instance,
null, instance, new object[] { });
int i = -1;
foreach (BuildItem item in buildItemGroup)
{
i++;
if (item == instance)
{
index = i;
break;
}
}
Include = instance.Include;
Type = instance.Name;
}
示例4: BuildWhen
public BuildWhen (XmlElement whenElement, Project parentProject)
{
this.parentProject = parentProject;
this.groupingCollection = new GroupingCollection (parentProject);
if (whenElement == null)
throw new ArgumentNullException ("whenElement");
this.whenElement = whenElement;
foreach (XmlElement xe in whenElement.ChildNodes) {
switch (xe.Name) {
case "ItemGroup":
BuildItemGroup big = new BuildItemGroup (xe, parentProject, null, true);
//big.BindToXml (xe);
groupingCollection.Add (big);
break;
case "PropertyGroup":
BuildPropertyGroup bpg = new BuildPropertyGroup (xe, parentProject, null, true);
//bpg.BindToXml (xe);
groupingCollection.Add (bpg);
break;
case "Choose":
BuildChoose bc = new BuildChoose (xe, parentProject);
groupingCollection.Add (bc);
break;
default:
throw new InvalidProjectFileException ( string.Format ("Invalid element '{0}' in When.", xe.Name));
}
}
}
示例5: ExpandAllIntoTaskItems3
public void ExpandAllIntoTaskItems3()
{
BuildPropertyGroup pg = new BuildPropertyGroup();
BuildItemGroup ig = new BuildItemGroup();
ig.AddItem(new BuildItem("Compile", "foo.cs"));
ig.AddItem(new BuildItem("Compile", "bar.cs"));
BuildItemGroup ig2 = new BuildItemGroup();
ig2.AddItem(new BuildItem("Resource", "bing.resx"));
Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
itemsByType["Compile"] = ig;
itemsByType["Resource"] = ig2;
Expander expander = new Expander(pg, itemsByType);
List<TaskItem> itemsOut = expander.ExpandAllIntoTaskItems("foo;bar;@(compile);@(resource)", null);
ObjectModelHelpers.AssertItemsMatch(@"
foo
bar
foo.cs
bar.cs
bing.resx
", itemsOut.ToArray());
}
示例6: TestCtor
public void TestCtor ()
{
BuildItemGroup big = new BuildItemGroup ();
Assert.AreEqual (String.Empty, big.Condition, "A1");
Assert.AreEqual (0, big.Count, "A2");
Assert.IsFalse (big.IsImported, "A3");
}
示例7: ParameterlessConstructor
public void ParameterlessConstructor()
{
BuildItemGroup group = new BuildItemGroup();
Assertion.AssertEquals(String.Empty, group.Condition);
Assertion.AssertEquals(false, group.IsPersisted);
Assertion.AssertEquals(0, group.Count);
Assertion.AssertEquals(false, group.IsImported);
}
示例8: XmlDocConstructor
public void XmlDocConstructor()
{
XmlDocument doc = new XmlDocument();
BuildItemGroup group = new BuildItemGroup(doc, true, new Project());
Assertion.AssertEquals(String.Empty, group.Condition);
Assert.AreNotEqual(null, group.ItemGroupElement);
Assertion.AssertEquals(0, group.Count);
Assertion.AssertEquals(true, group.IsImported);
}
示例9: SecondaryItemNotShadowedByPrimaryItem
public void SecondaryItemNotShadowedByPrimaryItem()
{
BuildItemGroup group1 = new BuildItemGroup();
group1.AddNewItem("i1", "a1");
Hashtable table1 = new Hashtable(StringComparer.OrdinalIgnoreCase);
table1.Add("i1", group1);
Lookup lookup = LookupHelpers.CreateLookup(table1);
lookup.EnterScope();
// Should return item from the secondary table.
Assertion.AssertEquals("a1", lookup.GetItems("i1")[0].FinalItemSpec);
}
示例10: XmlElementConstructor
public void XmlElementConstructor()
{
XmlElement ig = CreatePersistedItemGroupElement();
BuildItemGroup group = new BuildItemGroup(ig, false, new Project());
Assertion.AssertEquals("c", group.Condition);
Assertion.AssertEquals(ig, group.ItemGroupElement);
Assertion.AssertEquals(ig.ParentNode, group.ParentElement);
Assertion.AssertEquals(2, group.Count);
Assertion.AssertEquals(false, group.IsImported);
Assertion.AssertEquals("ci1", group[0].Condition);
Assertion.AssertEquals("i1", group[0].Include);
Assertion.AssertEquals("ci2", group[1].Condition);
Assertion.AssertEquals("i2", group[1].Include);
}
示例11: TestAddNewItem1
public void TestAddNewItem1 ()
{
string name = "name";
string include = "a;b;c";
BuildItemGroup big = new BuildItemGroup ();
BuildItem bi = big.AddNewItem (name, include);
Assert.AreEqual (String.Empty, bi.Condition, "A1");
Assert.AreEqual (String.Empty, bi.Exclude, "A2");
Assert.AreEqual (include, bi.FinalItemSpec, "A3");
Assert.AreEqual (include, bi.Include, "A4");
Assert.IsFalse (bi.IsImported, "A5");
Assert.AreEqual (name, bi.Name, "A6");
Assert.AreEqual (1, big.Count, "A7");
}
示例12: GenerateTestItems
/// <summary>
/// Generate a hashtable of items by type with a bunch of sample items, so that we can exercise
/// ItemExpander.ItemizeItemVector.
/// </summary>
/// <returns></returns>
/// <owner>RGoel</owner>
private Hashtable GenerateTestItems()
{
Hashtable itemGroupsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
// Set up our item group programmatically.
BuildItemGroup itemGroup = new BuildItemGroup();
itemGroupsByType["Compile"] = itemGroup;
BuildItem a = itemGroup.AddNewItem("Compile", "a.cs");
a.SetMetadata("WarningLevel", "4");
BuildItem b = itemGroup.AddNewItem("Compile", "b.cs");
b.SetMetadata("WarningLevel", "3");
BuildItemGroup itemGroup2 = new BuildItemGroup();
itemGroupsByType["Resource"] = itemGroup2;
BuildItem c = itemGroup2.AddNewItem("Resource", "c.resx");
return itemGroupsByType;
}
示例13: InitiallyNoItemsInBucketOfTypesInItemNames
public void InitiallyNoItemsInBucketOfTypesInItemNames()
{
// This bucket is for items of type "i"
string[] itemNames = new string[] { "i" };
// There are items of type "i" and "j" available in the project, though
BuildItemGroup group1 = new BuildItemGroup();
BuildItemGroup group2 = new BuildItemGroup();
group1.AddNewItem("i", "i1");
group2.AddNewItem("j", "j1");
Hashtable items = new Hashtable(StringComparer.OrdinalIgnoreCase);
items.Add("i", group1);
items.Add("j", group2);
Lookup lookup = LookupHelpers.CreateLookup(items);
ItemBucket bucket = new ItemBucket(itemNames, new Dictionary<string, string>(), lookup, 0);
// No items of type i
Assertion.AssertEquals(0, bucket.Lookup.GetItems("i1").Count);
// Items of type j, however, are visible
Assertion.AssertEquals(1, bucket.Lookup.GetItems("j").Count);
}
示例14: CantModifyThroughEnumerator
public void CantModifyThroughEnumerator()
{
BuildItemGroup ig = new BuildItemGroup();
BuildItem i1 = new BuildItem("name1", "value1");
i1.SetMetadata("myMetaName", "myMetaValue");
ig.AddItem(i1);
BuildItemGroupProxy proxy = new BuildItemGroupProxy(ig);
Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);
foreach (DictionaryEntry item in proxy)
{
list.Add(item.Key, item.Value);
}
// Change the item
Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
((TaskItem)list["name1"]).ItemSpec = "newItemSpec";
((TaskItem)list["name1"]).SetMetadata("newMetadata", "newMetadataValue");
// We did change our copy
Assertion.AssertEquals("newItemSpec", ((TaskItem)list["name1"]).ItemSpec);
Assertion.AssertEquals("newMetadataValue", ((TaskItem)list["name1"]).GetMetadata("newMetadata"));
Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));
// But get the item again
list = new Hashtable(StringComparer.OrdinalIgnoreCase);
foreach (DictionaryEntry item in proxy)
{
list.Add(item.Key, item.Value);
}
// Item value and metadata hasn't changed
Assertion.AssertEquals("value1", ((TaskItem)list["name1"]).ItemSpec);
Assertion.AssertEquals("", ((TaskItem)list["name1"]).GetMetadata("newMetadata"));
Assertion.AssertEquals("myMetaValue", ((TaskItem)list["name1"]).GetMetadata("myMetaName"));
}
示例15: SetupMembers
private void SetupMembers()
{
pg1 = new BuildPropertyGroup();
pg1.SetProperty("foo", "bar");
pg1.SetProperty("abc", "true");
pg1.SetProperty("Unit", "inches");
pg2 = new BuildPropertyGroup();
pg2.SetProperty("foo", "bar");
pg2.SetProperty("abc", "true");
pg3 = new BuildPropertyGroup();
// These Choose objects are only suitable for
// holding a place in the GroupingCollection.
choose1 = new Choose();
choose2 = new Choose();
choose3 = new Choose();
ig1 = new BuildItemGroup();
ig1.AddNewItem("x", "x1");
ig1.AddNewItem("x", "x2");
ig1.AddNewItem("y", "y1");
ig1.AddNewItem("y", "y2");
ig1.AddNewItem("y", "y3");
ig1.AddNewItem("y", "y4");
ig2 = new BuildItemGroup();
ig2.AddNewItem("jacksonfive", "germaine");
ig2.AddNewItem("jacksonfive", "tito");
ig2.AddNewItem("jacksonfive", "michael");
ig2.AddNewItem("jacksonfive", "latoya");
ig2.AddNewItem("jacksonfive", "janet");
ig3 = new BuildItemGroup();
}