本文整理汇总了C#中Microsoft.Build.Utilities.TaskItem.SetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# TaskItem.SetMetadata方法的具体用法?C# TaskItem.SetMetadata怎么用?C# TaskItem.SetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Utilities.TaskItem
的用法示例。
在下文中一共展示了TaskItem.SetMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendItemWithMissingAttribute
public void AppendItemWithMissingAttribute()
{
// Construct the task items.
TaskItem i = new TaskItem();
i.ItemSpec = "MySoundEffect.wav";
i.SetMetadata("Name", "Kenny");
i.SetMetadata("Access", "Private");
TaskItem j = new TaskItem();
j.ItemSpec = "MySplashScreen.bmp";
j.SetMetadata("Name", "Cartman");
j.SetMetadata("HintPath", @"c:\foo");
j.SetMetadata("Access", "Public");
CommandLineBuilderExtension c = new CommandLineBuilderExtension();
c.AppendSwitchIfNotNull
(
"/myswitch:",
new ITaskItem[] { i, j },
new string[] { "Name", "HintPath", "Access" },
null
);
Assert.Equal(@"/myswitch:MySoundEffect.wav,Kenny /myswitch:MySplashScreen.bmp,Cartman,c:\foo,Public", c.ToString());
}
示例2: Build
public void Build()
{
RegexCompiler task = new RegexCompiler();
task.BuildEngine = new MockBuild();
task.OutputDirectory = TaskUtility.TestDirectory;
task.AssemblyName = "MSBuild.Community.RegularExpressions.dll";
task.AssemblyTitle = "MSBuild.Community.RegularExpressions";
task.AssemblyDescription = "MSBuild Community Tasks Regular Expressions";
task.AssemblyCompany = "MSBuildTasks";
task.AssemblyProduct = "MSBuildTasks";
task.AssemblyCopyright = "Copyright (c) MSBuildTasks 2008";
task.AssemblyVersion = "1.0.0.0";
task.AssemblyFileVersion = "1.0.0.0";
task.AssemblyInformationalVersion = "1.0.0.0";
task.AssemblyKeyFile = @"..\..\..\MSBuild.Community.Tasks\MSBuild.Community.Tasks.snk";
List<ITaskItem> expressions = new List<ITaskItem>();
TaskItem item1 = new TaskItem("TextRegex");
item1.SetMetadata("Pattern", @"\G[^<]+");
item1.SetMetadata("Options", "RegexOptions.Singleline | RegexOptions.Multiline");
item1.SetMetadata("IsPublic", "true");
TaskItem item2 = new TaskItem("CommentRegex");
item2.SetMetadata("Pattern", @"\G<%--(([^-]*)-)*?-%>");
item2.SetMetadata("Options", "RegexOptions.Singleline | RegexOptions.Multiline");
item2.SetMetadata("IsPublic", "true");
task.RegularExpressions = new ITaskItem[] {item1, item2};
bool result = task.Execute();
Assert.IsTrue(result);
}
示例3: Execute
public override bool Execute()
{
Regex packageNameRegex = new Regex(PackageNameRegex);
List<ITaskItem> packageNameItems = new List<ITaskItem>();
foreach (string packageDrop in PackageDrops)
{
if (!Directory.Exists(packageDrop))
{
Log.LogWarning("PackageDrop does not exist - '{0}'", packageDrop);
continue;
}
IEnumerable<ITaskItem> packages = Directory.GetFiles(packageDrop).Select(f => new TaskItem(Path.GetFileNameWithoutExtension(f)));
foreach (ITaskItem package in packages)
{
Match m = packageNameRegex.Match(package.ItemSpec);
if (m.Success)
{
TaskItem packageName = new TaskItem(m.Groups[0].Value);
packageName.SetMetadata("PackageName", m.Groups[1].Value);
packageName.SetMetadata("PackageVersion", m.Groups[2].Value);
packageName.SetMetadata("PrereleaseVersion", m.Groups[3].Value);
packageNameItems.Add(packageName);
}
}
}
PackageNames = packageNameItems?.OrderBy(an => an.ItemSpec.ToString(), StringComparer.Ordinal)?.ToArray();
return true;
}
示例4: Execute
public override bool Execute ()
{
assemblies = new ITaskItem [assembly_files.Length];
for (int i = 0; i < assemblies.Length; i++) {
string file = assembly_files [i].ItemSpec;
AssemblyName an = AssemblyName.GetAssemblyName (file);
TaskItem item = new TaskItem (an.FullName);
item.SetMetadata ("Version", an.Version.ToString ());
byte[] pk = an.GetPublicKeyToken ();
string pkStr = pk != null? ByteArrayToString (pk) : "null";
item.SetMetadata ("PublicKeyToken", pkStr);
CultureInfo culture = an.CultureInfo;
if (culture != null) {
string cn;
if (culture.LCID == CultureInfo.InvariantCulture.LCID)
cn = "neutral";
else
cn = culture.Name;
item.SetMetadata ("Culture", cn);
}
assemblies[i] = item;
}
return true;
}
示例5: Execute
public override bool Execute()
{
ArrayList list = new ArrayList();
foreach (ITaskItem item in AssemblyFiles)
{
AssemblyName an;
try
{
an = AssemblyName.GetAssemblyName(item.ItemSpec);
}
catch (BadImageFormatException e)
{
Log.LogErrorWithCodeFromResources("GetAssemblyIdentity.CouldNotGetAssemblyName", item.ItemSpec, e.Message);
continue;
}
catch (Exception e) when (ExceptionHandling.IsIoRelatedException(e))
{
Log.LogErrorWithCodeFromResources("GetAssemblyIdentity.CouldNotGetAssemblyName", item.ItemSpec, e.Message);
continue;
}
ITaskItem newItem = new TaskItem(an.FullName);
newItem.SetMetadata("Name", an.Name);
if (an.Version != null)
newItem.SetMetadata("Version", an.Version.ToString());
if (an.GetPublicKeyToken() != null)
newItem.SetMetadata("PublicKeyToken", ByteArrayToHex(an.GetPublicKeyToken()));
if (an.CultureInfo != null)
newItem.SetMetadata("Culture", an.CultureInfo.ToString());
item.CopyMetadataTo(newItem);
list.Add(newItem);
}
Assemblies = (ITaskItem[])list.ToArray(typeof(ITaskItem));
return !Log.HasLoggedErrors;
}
示例6: CreateFileItem
public static ITaskItem CreateFileItem(string sourcePath, string targetPath, string targetFramework)
{
TaskItem item = new TaskItem(sourcePath);
item.SetMetadata("TargetPath", targetPath);
item.SetMetadata("TargetFramework", targetFramework);
return item;
}
示例7: ResolveSDKFromRefereneAssemblyLocation
private static void ResolveSDKFromRefereneAssemblyLocation(string referenceName, string expectedPath)
{
// Create the engine.
MockEngine engine = new MockEngine();
TaskItem taskItem = new TaskItem(referenceName);
taskItem.SetMetadata("SDKName", "FakeSDK, Version=1.0");
TaskItem resolvedSDK = new TaskItem(@"C:\FakeSDK");
resolvedSDK.SetMetadata("SDKName", "FakeSDK, Version=1.0");
resolvedSDK.SetMetadata("TargetedSDKConfiguration", "Debug");
resolvedSDK.SetMetadata("TargetedSDKArchitecture", "X86");
TaskItem[] assemblies = new TaskItem[] { taskItem };
// Now, pass feed resolved primary references into ResolveAssemblyReference.
ResolveAssemblyReference t = new ResolveAssemblyReference();
t.BuildEngine = engine;
t.Assemblies = assemblies;
t.ResolvedSDKReferences = new ITaskItem[] { resolvedSDK };
t.SearchPaths = new String[] { @"C:\SomeOtherPlace" };
bool succeeded = Execute(t);
Assert.True(succeeded);
Assert.Equal(1, t.ResolvedFiles.Length);
Assert.Equal(0, engine.Errors);
Assert.Equal(0, engine.Warnings);
Assert.True(t.ResolvedFiles[0].ItemSpec.Equals(expectedPath, StringComparison.OrdinalIgnoreCase));
}
示例8: CreateDependencyItem
public static ITaskItem CreateDependencyItem(string sourcePath, string version, string targetFramework)
{
TaskItem item = new TaskItem(sourcePath);
if (version != null)
{
item.SetMetadata("Version", version);
}
item.SetMetadata("TargetFramework", targetFramework);
return item;
}
示例9: ToTaskItem
public TaskItem ToTaskItem()
{
var item = new TaskItem(OutputFilePath);
// For Fxo we output Link used by <Content> Item
if (!OutputCs)
{
item.SetMetadata("CopyToOutputDirectory", "PreserveNewest");
item.SetMetadata("Link", OutputLink);
}
return item;
}
示例10: SetupTaskItem
/*
* Method: SetupTaskItem
*
* Creates a valid task item that's modified later
*/
private TaskItem SetupTaskItem()
{
TaskItem item = new TaskItem();
item.SetMetadata(ComReferenceItemMetadataNames.guid, "{5C6D0C4D-D530-4B08-B22F-307CA6BFCB65}");
item.SetMetadata(ComReferenceItemMetadataNames.versionMajor, "1");
item.SetMetadata(ComReferenceItemMetadataNames.versionMinor, "0");
item.SetMetadata(ComReferenceItemMetadataNames.lcid, "0");
item.SetMetadata(ComReferenceItemMetadataNames.wrapperTool, "tlbimp");
return item;
}
示例11: Execute
public override bool Execute()
{
if (Assemblies == null || Assemblies.Length == 0)
return true;
List<ITaskItem> references = new List<ITaskItem>();
List<ITaskItem> nativeLibs = new List<ITaskItem>();
foreach (var assemblyItem in Assemblies)
{
try
{
if (!File.Exists(assemblyItem.ItemSpec))
{
Log.LogError($"File {assemblyItem.ItemSpec} does not exist, ensure you have built libraries before building the package.");
continue;
}
using (PEReader peReader = new PEReader(new FileStream(assemblyItem.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Delete | FileShare.Read)))
{
MetadataReader reader = peReader.GetMetadataReader();
foreach (var handle in reader.AssemblyReferences)
{
AssemblyReference reference = reader.GetAssemblyReference(handle);
TaskItem referenceItem = new TaskItem(reader.GetString(reference.Name));
assemblyItem.CopyMetadataTo(referenceItem);
referenceItem.SetMetadata("Version", reference.Version.ToString());
referenceItem.SetMetadata("AssemblyVersion", reference.Version.ToString());
references.Add(referenceItem);
}
for (int i = 1, count = reader.GetTableRowCount(TableIndex.ModuleRef); i <= count; i++)
{
var moduleRef = reader.GetModuleReference(MetadataTokens.ModuleReferenceHandle(i));
var moduleName = reader.GetString(moduleRef.Name);
TaskItem nativeLib = new TaskItem(moduleName);
assemblyItem.CopyMetadataTo(nativeLib);
nativeLibs.Add(nativeLib);
}
}
}
catch (InvalidOperationException)
{
// Ignore invalid assemblies
}
}
ReferencedAssemblies = references.ToArray();
ReferencedNativeLibraries = nativeLibs.ToArray();
return true;
}
示例12: CreateReferenceItem
static internal ITaskItem CreateReferenceItem(string itemSpec, string projectGuid, string package, string name)
{
TaskItem reference = new TaskItem(itemSpec);
if (projectGuid != null)
reference.SetMetadata(attributeProject, projectGuid);
if (package != null)
reference.SetMetadata("Package", package);
if (name != null)
reference.SetMetadata("Name", name);
return reference;
}
示例13: GetSourceFolder
private static ITaskItem[] GetSourceFolder(string folder)
{
var folderItem = new TaskItem(folder);
folderItem.SetMetadata("Test-name", "Test-Content");
return new ITaskItem[] { folderItem };
}
示例14: Execute
public override bool Execute()
{
// read the xml file and populate the JobsFound result
if (File.Exists(ConfigFile)) {
var doc = XDocument.Load(ConfigFile);
var jobs = from wj in doc.Root.Elements("WebJob")
select new {
RelPath = wj.Attribute("RelativePath").Value,
Schedule = wj.Attribute("Schedule").Value
};
var resultList = new List<ITaskItem>();
foreach (var job in jobs) {
var item = new TaskItem(job.RelPath);
item.SetMetadata("Schedule", job.Schedule);
resultList.Add(item);
}
JobsFound = resultList.ToArray();
}
else {
Log.LogMessage("web jobs config file not found at [{0}]", ConfigFile);
}
return !Log.HasLoggedErrors;
}
示例15: Execute
public override bool Execute ()
{
if (files == null || files.Length == 0)
//nothing to do
return true;
List<ITaskItem> outFiles = new List<ITaskItem> ();
for (int i = 0; i < files.Length; i ++) {
string file = files [i].ItemSpec;
string link = files [i].GetMetadata ("Link");
string definingProjectPath = files [i].GetMetadata ("DefiningProjectFullPath");
if (String.IsNullOrEmpty (link) && Path.IsPathRooted (file) && !string.IsNullOrEmpty (definingProjectPath)) {
file = Path.GetFullPath (file);
var projectDir = Path.GetFullPath (Path.GetDirectoryName (definingProjectPath));
if (projectDir.Length == 0 || projectDir [projectDir.Length - 1] != Path.DirectorySeparatorChar)
projectDir += Path.DirectorySeparatorChar;
if (file.StartsWith (projectDir)) {
// The file is in the same folder or a subfolder of the project that contains it.
// Use the relative path wrt the containing project as link.
var outFile = new TaskItem (files [i]);
outFile.SetMetadata ("Link", file.Substring (projectDir.Length));
outFiles.Add (outFile);
}
}
}
assignedFiles = outFiles.ToArray ();
return true;
}