本文整理汇总了C#中TaskItem.SetMetadata方法的典型用法代码示例。如果您正苦于以下问题:C# TaskItem.SetMetadata方法的具体用法?C# TaskItem.SetMetadata怎么用?C# TaskItem.SetMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TaskItem
的用法示例。
在下文中一共展示了TaskItem.SetMetadata方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessInclude
private void ProcessInclude (ITaskItem include_item, Dictionary <string, bool> excludedItems,
List <ITaskItem> includedItems)
{
string[] separatedPath;
FileInfo[] fileInfo;
string name = include_item.ItemSpec;
if (!HasWildcard (name)) {
if (!excludedItems.ContainsKey (Path.GetFullPath(name)))
includedItems.Add (include_item);
} else {
if (name.Split (Path.DirectorySeparatorChar).Length > name.Split (Path.AltDirectorySeparatorChar).Length) {
separatedPath = name.Split (new char [] {Path.DirectorySeparatorChar},
StringSplitOptions.RemoveEmptyEntries);
} else {
separatedPath = name.Split (new char [] {Path.AltDirectorySeparatorChar},
StringSplitOptions.RemoveEmptyEntries);
}
if (separatedPath.Length == 1 && separatedPath [0] == String.Empty)
return;
int offset = 0;
if (Path.IsPathRooted (name)) {
baseDirectory = new DirectoryInfo (Path.GetPathRoot (name));
if (IsRunningOnWindows)
// skip the "drive:"
offset = 1;
}
string full_path = Path.GetFullPath (Path.Combine (Environment.CurrentDirectory, include_item.ItemSpec));
fileInfo = ParseIncludeExclude (separatedPath, offset, baseDirectory);
int wildcard_offset = full_path.IndexOf ("**");
foreach (FileInfo fi in fileInfo) {
string itemName = fi.FullName;
if (!Path.IsPathRooted (name) && itemName.Length > baseDirectory.FullName.Length && itemName.StartsWith (baseDirectory.FullName))
itemName = itemName.Substring (baseDirectory.FullName.Length + 1);
if (!excludedItems.ContainsKey (itemName) && !excludedItems.ContainsKey (Path.GetFullPath (itemName))) {
TaskItem item = new TaskItem (include_item);
item.ItemSpec = itemName;
if (wildcard_offset >= 0) {
string rec_dir = Path.GetDirectoryName (fi.FullName.Substring (wildcard_offset));
if (rec_dir.Length > 0)
rec_dir += Path.DirectorySeparatorChar;
item.SetMetadata ("RecursiveDir", rec_dir);
}
includedItems.Add (item);
}
}
}
}
示例2: Execute
public override bool Execute()
{
ArrayList items = new ArrayList();
ArrayList configs = new ArrayList();
// ItemSpec holds the filename or path of an Item
string metaprojFile = _solution.ItemSpec + ".metaproj.filtered";
var exists = false;
// Check the metaproj file exists
// otherwise warn it has to be emitted thanks to 'set MSBuildEmitSolution=1'
if (!File.Exists(metaprojFile))
{
metaprojFile = _solution.ItemSpec + ".metaproj";
if (!File.Exists(metaprojFile))
{
Log.LogWarning("The metaproj file " +
metaprojFile + " does not exist. You can emit it"
+ " by setting MSBuildEmitSolution to 1 while"
+ " calling MsBuild.");
}
else
exists = true;
}
else
exists = true;
if (exists)
{
try
{
// Load metaproj file
XDocument metaproj = XDocument.Load(metaprojFile);
// Parse metaproj file
var projectsConfigurations = metaproj.Root
.Descendants("ProjectConfiguration"); // empty namespace
foreach (var projectConfiguration in projectsConfigurations)
{
if (projectConfiguration
.Attribute("BuildProjectInSolution").Value == "True")
{
Project project = new Project();
TaskItem item = new TaskItem();
item.ItemSpec = projectConfiguration
.Attribute("AbsolutePath").Value;
var configAndPlatform = projectConfiguration.Value;
if (configAndPlatform == null)
continue;
var configSplitted = configAndPlatform.Split('|');
if (configSplitted.Length == 0)
continue;
project.Load(item.ItemSpec);
item.SetMetadata("Configuration", configSplitted[0]);
item.SetMetadata("Platform", configSplitted[1]);
items.Add(item);
}
}
}
catch (Exception ex)
{
Log.LogError("Error trying to load metaproj file " +
metaprojFile + ". " + ex.Message);
}
}
// Populate the "ProjectsFilesToBuild" output items
_projectsFilesToBuild = (ITaskItem[])items
.ToArray(typeof(ITaskItem));
// Log.HasLoggedErrors is true if the task logged any errors -- even
// if they were logged from a task's constructor or property setter.
// As long as this task is written to always log an error when it
// fails, we can reliably return HasLoggedErrors.
return !Log.HasLoggedErrors;
}
示例3: Execute
/// <summary>
/// Executes this instance.
/// </summary>
public override bool Execute() {
if (this.DestinationTemplates.Length != this.SourceTemplates.Length) {
this.Log.LogError("SourceTemplates array has length {0} while DestinationTemplates array has length {1}, but must equal.", this.SourceTemplates.Length, this.DestinationTemplates.Length);
}
if (this.SourceProjects.Length != this.SourceTemplates.Length) {
this.Log.LogError("SourceTemplates array has length {0} while SourceProjects array has length {1}, but must equal.", this.SourceTemplates.Length, this.SourceProjects.Length);
}
var projectItemsToCopy = new List<ITaskItem>();
for (int iTemplate = 0; iTemplate < this.SourceTemplates.Length; iTemplate++) {
ITaskItem sourceTemplateTaskItem = this.SourceTemplates[iTemplate];
var template = XElement.Load(sourceTemplateTaskItem.ItemSpec);
var templateContentElement = template.Element(XName.Get("TemplateContent", VSTemplateNamespace));
var projectElement = templateContentElement.Element(XName.Get("Project", VSTemplateNamespace));
if (projectElement == null) {
Log.LogMessage("Skipping merge of \"{0}\" with a project because no project was referenced from the template.", sourceTemplateTaskItem.ItemSpec);
continue;
}
var projectPath = this.SourceProjects[iTemplate].ItemSpec;
var projectDirectory = Path.GetDirectoryName(Path.Combine(Path.GetDirectoryName(sourceTemplateTaskItem.GetMetadata("FullPath")), projectElement.Attribute("File").Value));
Log.LogMessage("Merging project \"{0}\" with \"{1}\".", projectPath, sourceTemplateTaskItem.ItemSpec);
var sourceProject = new Project();
sourceProject.Load(projectPath);
var projectItems = sourceProject.EvaluatedItems.Cast<BuildItem>().Where(item => this.ProjectItemTypes.Contains(item.Name));
// Figure out where every project item is in source, and where it will go in the destination,
// taking into account a given maximum path length that may require that we shorten the path.
PathSegment root = new PathSegment();
root.Add(projectItems.Select(item => item.Include));
root.EnsureSelfAndChildrenNoLongerThan(this.MaximumRelativePathLength);
// Collect the project items from the project that are appropriate
// to include in the .vstemplate file.
foreach (var folder in root.SelfAndDescendents.Where(path => !path.IsLeaf && path.LeafChildren.Any())) {
XElement parentNode = projectElement;
parentNode = FindOrCreateParent(folder.CurrentPath, projectElement);
if (folder.NameChanged) {
parentNode.SetAttributeValue("TargetFolderName", folder.OriginalName);
}
foreach (var item in folder.LeafChildren) {
var itemName = XName.Get("ProjectItem", VSTemplateNamespace);
// The project item MAY be hard-coded in the .vstemplate file, under the original name.
var projectItem = parentNode.Elements(itemName).FirstOrDefault(el => string.Equals(el.Value, Path.GetFileName(item.OriginalName), StringComparison.OrdinalIgnoreCase));
if (projectItem == null) {
projectItem = new XElement(itemName, item.CurrentName);
parentNode.Add(projectItem);
}
if (item.NameChanged) {
projectItem.Value = item.CurrentName; // set Value in case it was a hard-coded item in the .vstemplate file.
projectItem.SetAttributeValue("TargetFileName", item.OriginalName);
}
if (this.ReplaceParametersExtensions.Contains(Path.GetExtension(item.OriginalPath))) {
projectItem.SetAttributeValue("ReplaceParameters", "true");
}
}
}
template.Save(this.DestinationTemplates[iTemplate].ItemSpec);
foreach (var pair in root.LeafDescendents) {
TaskItem item = new TaskItem(Path.Combine(Path.GetDirectoryName(this.SourceTemplates[iTemplate].ItemSpec), pair.OriginalPath));
string apparentSource = Path.Combine(Path.GetDirectoryName(this.SourceTemplates[iTemplate].ItemSpec), pair.OriginalPath);
var sourcePathException = this.SourcePathExceptions.FirstOrDefault(ex => string.Equals(ex.ItemSpec, apparentSource));
if (sourcePathException != null) {
item.SetMetadata("SourceFullPath", sourcePathException.GetMetadata("ActualSource"));
} else {
item.SetMetadata("SourceFullPath", Path.GetFullPath(apparentSource));
}
item.SetMetadata("DestinationFullPath", Path.GetFullPath(Path.Combine(Path.GetDirectoryName(this.DestinationTemplates[iTemplate].ItemSpec), pair.CurrentPath)));
item.SetMetadata("RecursiveDir", Path.GetDirectoryName(this.SourceTemplates[iTemplate].ItemSpec));
item.SetMetadata("Transform", this.ReplaceParametersExtensions.Contains(Path.GetExtension(pair.OriginalName)) ? "true" : "false");
projectItemsToCopy.Add(item);
}
}
this.ProjectItems = projectItemsToCopy.ToArray();
return !Log.HasLoggedErrors;
}
示例4: CreateExtraFile
private TaskItem CreateExtraFile(string extraFile, ITaskItem projectItem)
{
string path = BuildTaskUtility.ExpandEnvironmentVariables(extraFile);
string fullPath = Path.GetFullPath(path);
if (!File.Exists(fullPath))
{
Log.LogWarning("Cannot find extra file {0} for project {1}", extraFile, projectItem.ItemSpec);
return null;
}
TaskItem file = new TaskItem(path);
bool doReplacements = TransmorgificationUtilities.ValidMimeTypeForReplacements(extraFile);
file.SetMetadata("DoReplacements", doReplacements.ToString().ToLowerInvariant());
file.SetMetadata("ItemCollection", "Extra");
file.SetMetadata("ParentProject", projectItem.ItemSpec);
file.SetMetadata("ProjectDir", projectItem.GetMetadata("RelativeDir"));
return file;
}
示例5: Execute
public override bool Execute()
{
try
{
List<ITaskItem> contentsList = new List<ITaskItem>();
List<ITaskItem> dependencyList = new List<ITaskItem>();
List<ITaskItem> templateList = new List<ITaskItem>();
HashSet<Guid> guids = new HashSet<Guid>();
ProjectEx.Task = this;
foreach (ITaskItem projectItem in projectFiles)
{
string currentDirectory = Environment.CurrentDirectory;
ProjectEx project = new ProjectEx(projectItem);
project.Load();
Environment.CurrentDirectory = Path.GetDirectoryName(
project.FullFileName);
//Retrieve the list of Guids defined in the project, for later replacement.
string projectGuid = project.GetEvaluatedProperty("ProjectGuid");
if (!string.IsNullOrEmpty(projectGuid))
{
try
{
Guid guidProject = new Guid(projectGuid);
if (!guids.Contains(guidProject))
{
guids.Add(guidProject);
}
}
catch (FormatException)
{
Log.LogWarning("Project {0} has specified an ProjectGuid property not in the format of a Guid.", projectItem.ItemSpec);
}
}
string emulatorId = project.GetEvaluatedProperty("EmulatorId");
if (!string.IsNullOrEmpty(emulatorId))
{
try
{
Guid guidEmulator = new Guid(emulatorId);
if (!guids.Contains(guidEmulator))
{
guids.Add(guidEmulator);
}
}
catch (FormatException)
{
Log.LogWarning("Project {0} has specified an EmulatorId property not in the format of a Guid.", projectItem.ItemSpec);
}
}
//Select all the files referenced by the project.
foreach (string groupName in ProjectEx.FileGroups)
{
foreach (_BE.ProjectItem buildItem in project.MsBuildProject.GetItemsIgnoringCondition(groupName))
{
if (TransmorgificationUtilities.IsInRestrictedList(buildItem.Xml.Include))
{
Log.LogMessage("Skipping restricted file {0} in project {1}", buildItem.EvaluatedInclude, projectItem.ItemSpec);
continue;
}
else if (!File.Exists(buildItem.EvaluatedInclude)) // .GetMetadata("FullPath").EvaluatedValue))
{
Log.LogWarning("Cannot find file {0} referenced in project {1}", buildItem.EvaluatedInclude, projectItem.ItemSpec);
continue;
}
string fileName = buildItem.EvaluatedInclude;
if (Path.IsPathRooted(fileName))
{
Log.LogWarning("Project {0} references file {1} by absolute path, which is unsuitable for samples and templates", projectItem.ItemSpec, fileName);
}
TaskItem file = new TaskItem(fileName);
bool doReplacements = TransmorgificationUtilities.ValidMimeTypeForReplacements(buildItem.Xml.Include);
file.CopyMetadata(buildItem);
file.SetMetadata("DoReplacements", doReplacements.ToString().ToLowerInvariant());
file.SetMetadata("ItemCollection", buildItem.ItemType);
file.SetMetadata("ParentProject", projectItem.ItemSpec);
file.SetMetadata("ProjectDir", projectItem.GetMetadata("RelativeDir"));
string rootNamespace = project.GetEvaluatedProperty("RootNamespace");
if (rootNamespace == null)
{
rootNamespace = "";
}
file.SetMetadata("RootNamespace", rootNamespace);
contentsList.Add(file);
}
}
string templateIconFile = project.GetEvaluatedProperty("TemplateIconFile");
if (!string.IsNullOrEmpty(templateIconFile))
{
//.........这里部分代码省略.........
示例6: Execute
public override bool Execute()
{
switch (this.TaskAction)
{
case "GetReferencings":
{
Queue<string> queue = new Queue<string>();
IBtsCatalogExplorer2 explorer = ConnectExplorer();
GetReferencingList(explorer, this.Application, queue);
List<TaskItem> list = new List<TaskItem>();
foreach (string application in queue)
{
TaskItem item = new TaskItem();
item.itemSpec = application;
item.SetMetadata("DatabaseServer", this.DatabaseServer);
item.SetMetadata("Database", this.Database);
list.Add(item);
}
this.Output = list.ToArray();
this.OutputCount = list.Count;
this.Log.LogMessage("Setting OutputCount to {0}", this.OutputCount);
break;
}
case "GetReferences":
{
Queue<string> queue = new Queue<string>();
IBtsCatalogExplorer2 explorer = ConnectExplorer();
GetReferencesList(explorer, this.Application, queue);
List<TaskItem> list = new List<TaskItem>();
foreach (string application in queue)
{
TaskItem item = new TaskItem();
item.itemSpec = application;
item.SetMetadata("DatabaseServer", this.DatabaseServer);
item.SetMetadata("Database", this.Database);
list.Add(item);
}
this.Output = list.ToArray();
this.OutputCount = list.Count;
this.Log.LogMessage("Setting OutputCount to {0}", this.OutputCount);
break;
}
case "GetResources":
{
Queue<ITaskItem> queue = this.GetResourcesList(this.Application);
this.Output = queue.ToArray();
this.OutputCount = queue.Count;
return true;
}
case "GetList":
{
Queue<ITaskItem> queue = new Queue<ITaskItem>();
this.GetList(queue);
this.Output = queue.ToArray();
this.OutputCount = queue.Count;
return true;
}
default:
{
Log.LogError("Unrecognized Task Action {0}", this.TaskAction);
return false;
}
}
return true;
}
示例7: GetResourcesList
private Queue<ITaskItem> GetResourcesList(string name)
{
Queue<ITaskItem> list = new Queue<ITaskItem>();
using (Group group = this.ConnectGroup())
{
foreach (Microsoft.BizTalk.ApplicationDeployment.Application application in group.Applications)
{
if (application.Name == name)
{
Log.LogMessage("Inspecting Application {0}...", name);
foreach (Resource resource in application.ResourceCollection)
{
bool dynamic = false;
Log.LogMessage("Inspecting Resource {0}", resource.Luid);
ITaskItem task = new TaskItem();
task.ItemSpec = resource.Luid;
Log.LogMessage("Name: {0}", resource.Luid);
task.SetMetadata("Identity", resource.Luid);
Log.LogMessage("Type: {0}", resource.ResourceType);
task.SetMetadata("Type", resource.ResourceType);
foreach (string key in resource.Properties.Keys)
{
Log.LogMessage("{0}: {1}", key, resource.Properties[key]);
task.SetMetadata(key, resource.Properties[key].ToString());
if (key == "IsDynamic")
dynamic = (bool)resource.Properties[key];
}
if(!dynamic)
list.Enqueue(task);
}
}
}
}
return OrderResourceList(list);
}
示例8: GetList
private void GetList(Queue<ITaskItem> list)
{
using (Group group = this.ConnectGroup())
{
foreach (Microsoft.BizTalk.ApplicationDeployment.Application application in group.Applications)
{
TaskItem task = new TaskItem();
task.ItemSpec = application.Name;
task.SetMetadata("Identity", application.Name);
if (!string.IsNullOrWhiteSpace(application.Description))
task.SetMetadata("Description", application.Description);
task.SetMetadata("IsDefault", application.IsDefault.ToString());
task.SetMetadata("IsSystem", application.IsSystem.ToString());
//task.SetMetadata("Status", application.Status.ToString());
list.Enqueue(task);
}
}
}
示例9: InternalExecute
/// <summary>
/// Performs the action of this task.
/// </summary>
protected override void InternalExecute()
{
if (!this.TargetingLocalMachine())
{
return;
}
switch (this.TaskAction)
{
case AnalyseTaskAction:
this.analyseOnly = true;
break;
case DetokeniseTaskAction:
break;
case ReportTaskAction:
this.analyseOnly = true;
this.report = true;
break;
default:
this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Invalid TaskAction passed: {0}", this.TaskAction));
return;
}
this.tokenDictionary = new SortedDictionary<string, string>();
this.DoDetokenise();
if (this.tokenDictionary.Count > 0 && this.report)
{
this.TokenReport = new TaskItem[this.tokenDictionary.Count];
int i = 0;
foreach (var s in this.tokenDictionary)
{
ITaskItem t = new TaskItem(s.Key);
t.SetMetadata("Files", s.Value);
this.TokenReport[i] = t;
i++;
}
}
}
示例10: InternalExecute
/// <summary>
/// Performs the action of this task.
/// </summary>
protected override void InternalExecute()
{
if (!this.TargetingLocalMachine())
{
return;
}
switch (this.TaskAction)
{
case AnalyseTaskAction:
this.analyseOnly = true;
break;
case DetokeniseTaskAction:
break;
case ReportTaskAction:
this.analyseOnly = true;
this.report = true;
break;
default:
this.Log.LogError(string.Format(CultureInfo.CurrentCulture, "Invalid TaskAction passed: {0}", this.TaskAction));
return;
}
this.tokenDictionary = new SortedDictionary<string, string>();
this.DoDetokenise();
if (this.tokenDictionary.Count > 0 && this.report)
{
this.TokenReport = new TaskItem[this.tokenDictionary.Count];
int i = 0;
foreach (var s in this.tokenDictionary)
{
ITaskItem t = new TaskItem(s.Key);
t.SetMetadata("Files", s.Value);
this.TokenReport[i] = t;
i++;
}
if (this.ReportUnusedTokens)
{
this.unusedTokens = new SortedDictionary<string, string>();
// Find unused tokens.
if (this.collectionMode)
{
if (this.ReplacementValues != null)
{
// we need to look in the ReplacementValues for a match
foreach (ITaskItem token in this.ReplacementValues)
{
if (!this.tokenDictionary.ContainsKey(token.ToString()) && !this.unusedTokens.ContainsKey(token.ToString()))
{
this.unusedTokens.Add(token.ToString(), string.Empty);
}
}
}
if (this.commandLineDictionary != null)
{
foreach (string s in this.commandLineDictionary.Keys)
{
if (!this.tokenDictionary.ContainsKey(s) && !this.unusedTokens.ContainsKey(s))
{
this.unusedTokens.Add(s, string.Empty);
}
}
}
}
else
{
foreach (BuildProperty pp in this.project.EvaluatedProperties)
{
if (!this.tokenDictionary.ContainsKey(pp.Name) && !this.unusedTokens.ContainsKey(pp.Name))
{
this.unusedTokens.Add(pp.Name, string.Empty);
}
}
}
this.UnusedTokens = new TaskItem[this.unusedTokens.Count];
i = 0;
foreach (var s in this.unusedTokens)
{
ITaskItem t = new TaskItem(s.Key);
this.UnusedTokens[i] = t;
i++;
}
}
}
}