本文整理汇总了C#中Microsoft.Build.BuildEngine.BuildItem.SetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# BuildItem.SetMetadata方法的具体用法?C# BuildItem.SetMetadata怎么用?C# BuildItem.SetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.BuildEngine.BuildItem
的用法示例。
在下文中一共展示了BuildItem.SetMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDependencies
public void AddDependencies(ProjectInfo[] depends)
{
foreach (ProjectInfo proj in depends)
{
BuildItem bi = new BuildItem("Reference", proj.AssemblyName);
bi.SetMetadata("SpecificVersion", false.ToString());
bi.SetMetadata("HintPath", proj.AbsoluteOutputPath);
_psedoDepends.Add(new ProjectRef(bi, GetProjectPath));
}
}
示例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: 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"));
}
示例4: PropertyFunctionConsumingItemMetadata
public void PropertyFunctionConsumingItemMetadata()
{
MockLogger logger = new MockLogger();
Project project = ObjectModelHelpers.CreateInMemoryProject(@"
<Project ToolsVersion=`3.5` xmlns=`msbuildnamespace`>
</Project>
", logger);
BuildPropertyGroup pg = new BuildPropertyGroup();
pg.SetProperty("SomePath", @"c:\some\path");
BuildItemGroup ig = new BuildItemGroup();
BuildItem item = new BuildItem("Compile", "fOo.Cs");
item.SetMetadata("SomeMeta", "fOo.Cs");
ig.AddItem(item);
Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
itemsByType["Compile"] = ig;
Expander expander = new Expander(pg, itemsByType, ExpanderOptions.ExpandAll);
expander.SetMetadataInMetadataTable("Compile", "SomeMeta", "fOo.Cs");
string result = expander.ExpandAllIntoStringLeaveEscaped(@"$([System.IO.Path]::Combine($(SomePath),%(Compile.SomeMeta)))", null);
Assertion.AssertEquals(@"c:\some\path\fOo.Cs", result);
}
示例5: VerifyEscapeCharactersThrowExpectedException
/// <summary>
/// Loops through all of the Escape Characters to ensure the expected 'ArgumentException'
/// is thrown and that the exception message contains the Escape Character. If any
/// unexpected exceptions are thrown, they are not directly handled, thus will fail the calling
/// unit test with the exception information. And, if no exception is thrown, Assertion.Fail
/// is called, because the ArgumentException should have been thrown.
/// </summary>
/// <param name="testType">Type of test that you are calling from</param>
private void VerifyEscapeCharactersThrowExpectedException(TypeOfTest testType)
{
foreach (char c in EscapableCharacters)
{
try
{
if (testType == TypeOfTest.ConstructorTest)
{
BuildItem item = new BuildItem(c.ToString(), "i");
}
else if (testType == TypeOfTest.SetNameTest)
{
BuildItem item = new BuildItem("n", "i");
item.Name = c.ToString();
}
else if (testType == TypeOfTest.SetMetadataTest)
{
BuildItem item = new BuildItem("n", "i");
item.SetMetadata(c.ToString(), "v");
}
Assertion.Fail(String.Format("Escape Character '{0}' didn't throw the expected ArgumentException", c.ToString()));
}
catch (ArgumentException expected)
{
Assertion.AssertEquals(true, expected.Message.Contains(c.ToString()));
}
}
}
示例6: CloneVirtual
public void CloneVirtual()
{
BuildItem item = new BuildItem("n", "i");
item.SetMetadata("m1", "v1");
item.SetMetadata("m2", "v2");
BuildItem clone = item.Clone();
Assertion.AssertEquals("v1", clone.GetMetadata("m1"));
Assertion.AssertEquals("v2", clone.GetMetadata("m2"));
clone.SetMetadata("m2", "newValue");
Assertion.AssertEquals("v2", item.GetMetadata("m2"));
Assertion.AssertEquals("newValue", clone.GetMetadata("m2"));
}
示例7: TestSetMetadata4
public void TestSetMetadata4 ()
{
item = new BuildItem ("name", "include");
item.SetMetadata ("Filename", "something");
}
示例8: TestSetMetadata2
public void TestSetMetadata2 ()
{
item = new BuildItem ("name", "include");
item.SetMetadata ("name", null);
}
示例9: TestHasMetadata1
public void TestHasMetadata1 ()
{
string itemName = "a";
string itemInclude = "a";
string metadataName = "name";
item = new BuildItem (itemName, itemInclude);
Assert.AreEqual (false, item.HasMetadata (metadataName), "A1");
item.SetMetadata (metadataName, "value");
Assert.AreEqual (true, item.HasMetadata (metadataName), "A2");
Assert.IsTrue (item.HasMetadata ("FullPath"), "A3");
Assert.IsTrue (item.HasMetadata ("RootDir"), "A4");
Assert.IsTrue (item.HasMetadata ("Filename"), "A5");
Assert.IsTrue (item.HasMetadata ("Extension"), "A6");
Assert.IsTrue (item.HasMetadata ("RelativeDir"), "A7");
Assert.IsTrue (item.HasMetadata ("Directory"), "A8");
Assert.IsTrue (item.HasMetadata ("RecursiveDir"), "A9");
Assert.IsTrue (item.HasMetadata ("Identity"), "A10");
Assert.IsTrue (item.HasMetadata ("ModifiedTime"), "A11");
Assert.IsTrue (item.HasMetadata ("CreatedTime"), "A12");
Assert.IsTrue (item.HasMetadata ("AccessedTime"), "A13");
}
示例10: OnAddResource
protected override void OnAddResource(BuildItem item)
{
item.SetMetadata("Generator", "ResXFileCodeGenerator");
}
示例11: AddContentBuildItem
public override BuildItem AddContentBuildItem(string absoluteFile)
{
string relativeFileName = FileManager.MakeRelative(absoluteFile, this.Directory);
BuildItem buildItem = null;
string extension = FileManager.GetExtension(absoluteFile);
buildItem = new BuildItem(FileManager.RemovePath(FileManager.RemoveExtension(absoluteFile)) + extension, relativeFileName.Replace("/", "\\"));
string name = FileManager.RemovePath(FileManager.RemoveExtension(relativeFileName));
buildItem.SetMetadata("Name", name);
mBuildItemDictionaries.Add(buildItem.Include.ToLower(), buildItem);
UpdateContentFile(absoluteFile.Replace("/", "\\"));
return buildItem;
}
示例12: GenerateLookup
private static Lookup GenerateLookup(BuildPropertyGroup properties)
{
BuildItemGroup items = new BuildItemGroup();
BuildItem item1 = new BuildItem("i0", "a1");
BuildItem item2 = new BuildItem("i0", "a2");
BuildItem item3 = new BuildItem("i0", "a3");
BuildItem item4 = new BuildItem("i0", "a4");
item1.SetMetadata("m", "m1");
item1.SetMetadata("n", "n1");
item2.SetMetadata("m", "m2");
item2.SetMetadata("n", "n2");
item3.SetMetadata("m", "m2");
item3.SetMetadata("n", "n2");
item4.SetMetadata("m", "m3");
item4.SetMetadata("n", "n3");
items.AddItem(item1);
items.AddItem(item2);
items.AddItem(item3);
items.AddItem(item4);
Hashtable itemsByName = new Hashtable(StringComparer.OrdinalIgnoreCase);
itemsByName.Add("i0", items);
Lookup lookup = LookupHelpers.CreateLookup(properties, itemsByName);
return lookup;
}
示例13: CreateBuildResult
private static BuildResult CreateBuildResult()
{
BuildItem buildItem1 = new BuildItem(null, "Item1");
BuildItem buildItem2 = new BuildItem("BuildItem2", "Item2");
BuildItem buildItem3 = BuildItem_Tests.GetXmlBackedItemWithDefinitionLibrary(); // default metadata m=m1 and o=o1
buildItem1.Include = "TestInclude1";
buildItem2.Include = "TestInclude2";
buildItem1.SetMetadata("m", "m1");
buildItem1.SetMetadata("n", "n1");
buildItem3.SetMetadata("n", "n1");
buildItem3.SetMetadata("o", "o2");
BuildItem[] taskItems = new BuildItem[3];
taskItems[0] = buildItem1;
taskItems[1] = buildItem2;
taskItems[2] = buildItem3;
Dictionary<object, object> dictionary = new Dictionary<object, object>();
dictionary.Add("TaskItems", taskItems);
BuildResult resultWithOutputs = new BuildResult(dictionary, new Hashtable(StringComparer.OrdinalIgnoreCase), true, 0, 1, 2, true, "Foo", "Fighter", 1, 2, 3);
resultWithOutputs.ResultByTarget.Add("ONE", Target.BuildState.CompletedSuccessfully);
resultWithOutputs.HandleId = 0;
resultWithOutputs.RequestId = 1;
return resultWithOutputs;
}
示例14: TryInvalidItemName
/// <summary>
/// Helper for trying invalid item names
/// </summary>
/// <param name="name"></param>
private void TryInvalidItemName(string name)
{
XmlDocument doc = new XmlDocument();
bool caughtException = false;
// Test the BuildItem ctor
try
{
BuildItem item = new BuildItem(doc, name, "someItemSpec", new ItemDefinitionLibrary(new Project()));
}
catch (ArgumentException ex)
{
Console.WriteLine(ex.Message);
caughtException = true;
}
Assertion.Assert(name, caughtException);
// Test the Name setter codepath
caughtException = false;
try
{
BuildItem item = new BuildItem(doc, "someName", "someItemSpec", new ItemDefinitionLibrary(new Project()));
item.Name = name;
}
catch (ArgumentException ex)
{
Console.WriteLine(ex.Message);
caughtException = true;
}
Assertion.Assert(name, caughtException);
// Test the metadata setter codepath
caughtException = false;
try
{
BuildItem item = new BuildItem(doc, "someName", "someItemSpec", new ItemDefinitionLibrary(new Project()));
item.SetMetadata(name, "someValue");
}
catch (ArgumentException ex)
{
Console.WriteLine(ex.Message);
caughtException = true;
}
Assertion.Assert(name, caughtException);
}
示例15: InvalidItemMetadataNameRename
public void InvalidItemMetadataNameRename()
{
bool fExceptionCaught = false;
BuildItem item = new BuildItem("my", "precioussss");
try
{
item.SetMetadata("Choose", "blah");
}
catch (InvalidOperationException)
{
fExceptionCaught = true;
}
Assertion.Assert(fExceptionCaught);
}