Example #1
0
 /// <include file='doc\Project.uex' path='docs/doc[@for="ProjectElement.RemoveFromProjectFile"]/*' />
 /// <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 void RemoveFromProjectFile()
 {
     ThrowIfDeleted();
     deleted = true;
     itemProject.projFile.RemoveItem(item);
     itemProject = null;
     item = null;
 }
Example #2
0
        /// <summary>
        /// Constructor to Wrap an existing MSBuild.Item
        /// Only have internal constructors as the only one who should be creating
        /// such object is the project itself (see Project.CreateFileNode()).
        /// </summary>
        /// <param name="project">Project that owns this item</param>
        /// <param name="existingItem">an MSBuild.Item; can be null if virtualFolder is true</param>
        /// <param name="virtualFolder">Is this item virtual (such as reference folder)</param>
        internal ProjectElement(Project project, MSBuild.Item existingItem, bool virtualFolder)
        {
            if (project == null)
                throw new ArgumentNullException("project", String.Format(SR.GetString(SR.AddToNullProjectError), existingItem.Include));
            if (!virtualFolder && existingItem == null)
                throw new ArgumentNullException("existingItem");

            // Keep a reference to project and item
            itemProject = project;
            item = existingItem;
            isVirtual = virtualFolder;
        }
Example #3
0
 /// <include file='doc\Project.uex' path='docs/doc[@for="ProjectElement.RefreshProperties"]/*' />
 /// <summary>
 /// Reevaluate all properties for the current item
 /// This should be call if you believe the property for this item
 /// may have changed since it was created/refreshed, or global properties
 /// this items depends on have changed.
 /// Be aware that there is a perf cost in calling this function.
 /// </summary>
 public void RefreshProperties()
 {
     ThrowIfDeleted();
     MSBuild.ItemGroup items = itemProject.projFile.EvaluatedItems;
     foreach (MSBuild.Item projectItem in items)
     {
         if (projectItem.Include == item.Include)
         {
             item = projectItem;
             return;
         }
     }
 }
Example #4
0
        /// <summary>
        /// Constructor to create a new MSBuild.Item 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(Project project, string itemPath, string itemType)
        {
            if (project == null)
                throw new ArgumentNullException("project", String.Format(SR.GetString(SR.AddToNullProjectError), itemPath));

            itemProject = project;

            // create and add the item to the project
            item = project.projFile.AddNewItem(itemType, itemPath);
            project.SetProjectFileDirty(true);
            this.RefreshProperties();
        }