Exemple #1
0
        /// <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);
            }
        }
Exemple #2
0
        public override bool Equals(object obj)
        {
            // Do they reference the same element?
            if (Object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            MsBuildProjectElement msBuildProjElem = obj as MsBuildProjectElement;

            if (Object.ReferenceEquals(msBuildProjElem, null))
            {
                return(false);
            }

            // Do they reference the same project?
            if (!ItemProject.Equals(msBuildProjElem.ItemProject))
            {
                return(false);
            }

            // Do they have the same include?
            string include1 = GetMetadata(ProjectFileConstants.Include);
            string include2 = msBuildProjElem.GetMetadata(ProjectFileConstants.Include);

            // Unfortunately the checking for nulls have to be done again, since neither String.Equals nor String.Compare can handle nulls.
            // Virtual folders should not be handled here.
            if (include1 == null || include2 == null)
            {
                return(false);
            }

            return(String.Equals(include1, include2, StringComparison.OrdinalIgnoreCase));
        }
        /// <summary>
        /// Calling this method remove this item from the project file.
        /// Once the item is delete, you should not longer be using it.
        /// Note that the item should be removed from the hierarchy prior to this call.
        /// </summary>
        public override void RemoveFromProjectFile()
        {
            if (!Deleted)
            {
                ItemProject.BuildProject.RemoveItem(_item);
                ItemProject.SetProjectFileDirty(true);
            }

            base.RemoveFromProjectFile();
        }
        /// <summary>
        /// Constructor to create a new MSBuild.ProjectItem 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 MsBuildProjectElement(ProjectNode project, string itemPath, string itemType)
            : base(project)
        {
            Utilities.ArgumentNotNullOrEmpty("itemPath", itemPath);
            Utilities.ArgumentNotNullOrEmpty("itemType", itemType);

            // create and add the item to the project

            _item = project.BuildProject.AddItem(itemType, Microsoft.Build.Evaluation.ProjectCollection.Escape(itemPath))[0];
            ItemProject.SetProjectFileDirty(true);
        }