/// <summary> /// Set an attribute on the project element /// </summary> /// <param name="attributeName">Name of the attribute to set</param> /// <param name="attributeValue">Value to give to the attribute</param> public override void SetMetadata(string attributeName, string attributeValue) { Debug.Assert(String.Compare(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase) != 0, "Use rename as this won't work"); // Build Action is the type, not a property, so intercept if (String.Compare(attributeName, ProjectFileConstants.BuildAction, StringComparison.OrdinalIgnoreCase) == 0) { _item.ItemType = attributeValue; return; } // Check out the project file. if (!ItemProject.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } if (attributeValue == null) { _item.RemoveMetadata(attributeName); } else { _item.SetMetadataValue(attributeName, attributeValue); } }
/// <summary> /// Set an attribute on the project element /// </summary> /// <param name="attributeName">Name of the attribute to set</param> /// <param name="attributeValue">Value to give to the attribute. Use <c>null</c> to delete the metadata definition.</param> public void SetMetadata(string attributeName, string attributeValue) { Debug.Assert(String.Compare(attributeName, ProjectFileConstants.Include, StringComparison.OrdinalIgnoreCase) != 0, "Use rename as this won't work"); if (this.IsVirtual) { // For virtual node, use our virtual property collection if (virtualProperties.ContainsKey(attributeName)) { virtualProperties.Remove(attributeName); } virtualProperties.Add(attributeName, attributeValue); return; } // Build Action is the type, not a property, so intercept if (String.Equals(attributeName, ProjectFileConstants.BuildAction, StringComparison.OrdinalIgnoreCase)) { item.ItemType = attributeValue; return; } ThreadHelper.ThrowIfNotOnUIThread(); String currentValue = item?.GetMetadataValue(attributeName); bool changed; if (String.IsNullOrEmpty(currentValue) && String.IsNullOrEmpty(attributeValue)) { changed = false; } else { changed = String.Compare(currentValue, attributeValue) != 0; } if (changed) { // Check out the project file. if (!this.itemProject.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } if (attributeValue == null) { item.RemoveMetadata(attributeName); } else { item.SetMetadataValue(attributeName, attributeValue); } itemProject.SetProjectFileDirty(true); } }
public void RemoveMetadata(string name) { item.RemoveMetadata(name); }