public static void SetMetadataValue(MSBuild.ProjectItem item, string name, string value) { item.SetMetadataValue(name, value); }
private void ReplaceGuidMetadataIfExists(_BE.ProjectItem item, string metadataName) { string value = item.GetMetadata(metadataName).EvaluatedValue; if (!string.IsNullOrEmpty(value)) { try { Guid g = new Guid(value); string replaceWith; if (guidDictionary.TryGetValue(g, out replaceWith)) { //VS Guid replacements don't include braces replaceWith = "{" + replaceWith + "}"; item.SetMetadataValue(metadataName, replaceWith); } } catch (FormatException) { Log.LogWarning("Item {0} has specified {1} metadata not in the format of a Guid.", item.EvaluatedInclude, metadataName); } } }
/// <summary> /// Add an item to the hierarchy based on the item path /// </summary> /// <param name="item">Item to add</param> /// <returns>Added node</returns> protected virtual HierarchyNode AddIndependentFileNode(MSBuild.ProjectItem item, IDictionary<string, HierarchyNode> parentNodeCache) { if (item == null) throw new ArgumentNullException("item"); if (parentNodeCache == null) throw new ArgumentNullException("parentNodeCache"); //Contract.Ensures(Contract.Result<HierarchyNode>() != null); // Make sure the item is within the project folder hierarchy. If not, link it. string linkPath = item.GetMetadataValue(ProjectFileConstants.Link); if (String.IsNullOrEmpty(linkPath)) { string projectFolder = new Uri(this.ProjectFolder).LocalPath; string itemPath = new Uri(Path.Combine(this.ProjectFolder, item.EvaluatedInclude)).LocalPath; if (!itemPath.StartsWith(projectFolder, StringComparison.OrdinalIgnoreCase)) { linkPath = Path.GetFileName(item.EvaluatedInclude); item.SetMetadataValue(ProjectFileConstants.Link, linkPath); } } HierarchyNode currentParent = GetItemParentNode(item, parentNodeCache); return AddFileNodeToNode(item, currentParent); }