Beispiel #1
0
        /// <summary>
        /// Removes an item from the main project file.
        /// </summary>
        /// <param name="itemToRemove"></param>
        /// <owner>RGoel</owner>
        public void RemoveItem
        (
            BuildItem itemToRemove
        )
        {
            error.VerifyThrowArgumentNull(itemToRemove, "itemToRemove");

            // Confirm that it's not an imported item.
            error.VerifyThrowInvalidOperation(!itemToRemove.IsImported, "CannotModifyImportedProjects");
            BuildItemGroup parentItemGroup;

            if (itemToRemove.ParentPersistedItem == null)
            {
                // This is either a persisted item that's actually declared in the project file,
                // or it's some kind of intermediate virtual item.

                // If the item doesn't have a parent BuildItemGroup associated with it, then it
                // must not be a persisted item that's actually declared in the project file.
                parentItemGroup = itemToRemove.ParentPersistedItemGroup;
                error.VerifyThrowInvalidOperation (parentItemGroup != null, "ObjectIsNotInProject");
            }
            else
            {
                // This is an evaluated item that came from a persisted item tag declared in
                // the project file.

                // If the item tag produced more than one evaluated item, then it's time to
                // split up the item tag into several new item tags.
                itemToRemove.SplitChildItemIfNecessary();

                error.VerifyThrow(itemToRemove.ParentPersistedItem != null, "No parent BuildItem for item to be removed.");
                itemToRemove = itemToRemove.ParentPersistedItem;

                error.VerifyThrow(itemToRemove.ParentPersistedItemGroup != null,
                    "No parent BuildItemGroup for item to be removed.");
                parentItemGroup = itemToRemove.ParentPersistedItemGroup;
            }

            parentItemGroup.RemoveItem(itemToRemove);

            if (parentItemGroup.Count == 0)
            {
                this.RemoveItemGroup(parentItemGroup);
            }

            this.MarkProjectAsDirty ();
        }