public void RemoveCodeFile(DocumentPath documentPath)
        {
            MsBuildProject container    = null;
            MsBuildItem    itemToRemove = null;

            foreach (var proj in this.Solution.Projects)
            {
                if (proj.Value.Name == documentPath.ProjectName)
                {
                    foreach (var item in proj.Value.Items)
                    {
                        if (item.DocumentPath.Equals(documentPath) && this.msBuildStoreAdapters.Any(a => a.ItemSupported(item)))
                        {
                            container    = proj.Value;
                            itemToRemove = item;
                            break;
                        }
                    }
                }
            }

            if (itemToRemove != null)
            {
                container.RemoveItem(itemToRemove);
            }
        }
Пример #2
0
        public void RemoveItem(MsBuildItem item)
        {
            if (!this.IsUsingDefaultItemsForItemType(item.ItemType))
            {
                this.Project.RemoveItem(item.Item);
            }

            if (this.fileSystem.File.Exists(item.FullPath))
            {
                this.fileSystem.File.Delete(item.FullPath);
            }

            this.items.Remove(item);
        }
Пример #3
0
        public IEnumerable <MsBuildItem> AddItem(string itemType, string unevaluatedInclude)
        {
            var result = new List <MsBuildItem>();

            if (this.IsUsingDefaultItemsForItemType(itemType))
            {
                string fullPath         = null;
                string projectDirectory = this.fileSystem.Path.GetDirectoryName(this.FullPath);
                if (this.fileSystem.Path.IsPathRooted(unevaluatedInclude))
                {
                    fullPath = this.fileSystem.Path.GetFullPath(unevaluatedInclude);
                }
                else
                {
                    fullPath = this.fileSystem.Path.GetFullPath(this.fileSystem.Path.Combine(projectDirectory, unevaluatedInclude));
                }

                if (!PathMaskHelper.DirectoryIsBaseOf(projectDirectory, fullPath))
                {
                    throw new InvalidOperationException($"Project {this.Name} is using default items for {itemType}, item path {fullPath} should be under project path {projectDirectory}.");
                }

                var          itemDirectory = this.fileSystem.Path.GetDirectoryName(fullPath);
                DocumentPath docPath       = new DocumentPath(
                    this.Name,
                    itemDirectory.Remove(0, projectDirectory.Length).Split(new char[] { this.fileSystem.Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries),
                    this.fileSystem.Path.GetFileName(fullPath));

                if (!this.fileSystem.File.Exists(fullPath))
                {
                    this.fileSystem.File.WriteAllText(fullPath, string.Empty);
                }

                var newItem = new MsBuildItem(docPath, fullPath, itemType, this);
                this.items.Add(newItem);
                result.Add(newItem);
            }
            else
            {
                foreach (var item in this.Project.AddItem(itemType, unevaluatedInclude))
                {
                    var newItem = new MsBuildItem(item, this);
                    this.items.Add(newItem);
                    result.Add(newItem);
                }
            }

            return(result);
        }
 public virtual bool ItemSupported(MsBuildItem item)
 {
     return(item.ItemType != null && item.ItemType != this.itemType);
 }