/// <summary> /// Constructor to create a new MSBuild.BuildItem and add it to the project /// Only have internal constructors as the only one who should be creating /// such object is the project itself (see Project.CreateFileNode()). /// </summary> internal ProjectElement(ProjectNode project, string itemPath, string itemType) { if (project == null) throw new ArgumentNullException("project", String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.AddToNullProjectError), itemPath)); itemProject = project; // create and add the item to the project item = project.BuildProject.AddNewItem(itemType, itemPath); project.SetProjectFileDirty(true); this.RefreshProperties(); }
/// <summary> /// Constructor to create a new MSBuild.BuildItem and add it to the project /// Only have internal constructors as the only one who should be creating /// such object is the project itself (see Project.CreateFileNode()). /// </summary> internal ProjectElement(ProjectNode project, string itemPath, string itemType) { if (project == null) { throw new ArgumentNullException("project", String.Format(CultureInfo.CurrentCulture, SR.GetString(SR.AddToNullProjectError), itemPath)); } itemProject = project; // create and add the item to the project item = project.BuildProject.AddNewItem(itemType, itemPath); project.SetProjectFileDirty(true); this.RefreshProperties(); }
/// <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 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.Compare(attributeName, ProjectFileConstants.BuildAction, StringComparison.OrdinalIgnoreCase) == 0) { item.ItemType = attributeValue; return; } // Check out the project file. if (!this.itemProject.QueryEditProjectFile(false)) { throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED); } if (attributeValue == null) { item.RemoveMetadata(attributeName); } else { MSBuildItem.SetMetadataValue(item, attributeName, attributeValue); } itemProject.SetProjectFileDirty(true); }