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); } }
public MsBuildItem(DocumentPath documentPath, string fullPath, string itemType, MsBuildProject project) { this.documentPath = documentPath; this.fullPath = fullPath; this.itemType = itemType; this.project = project; }
public virtual void Remove(CodeFile codeFile, MsBuildProject msBuildProject) { var relativeItemPath = this.GetProjectRelativePath(codeFile.Location, msBuildProject); var existingItems = msBuildProject.FindProjectItems(relativeItemPath).ToList(); foreach (var item in existingItems) { msBuildProject.RemoveItem(item); } }
public virtual void AddOrUpdate(CodeFile codeFile, MsBuildProject msBuildProject) { var relativeItemPath = this.GetProjectRelativePath(codeFile.Location, msBuildProject); var fullItemPath = this.fileSystem.Path.GetFullPath(this.fileSystem.Path.Combine(this.fileSystem.Path.GetDirectoryName(msBuildProject.FullPath), relativeItemPath)); var existingItems = msBuildProject.FindProjectItems(fullItemPath).ToList(); if (existingItems.All(i => i.ItemType != this.itemType)) { msBuildProject.AddItem(this.itemType, relativeItemPath); } this.UpdateFileContent(fullItemPath, codeFile.SourceCodeText); }
private void LoadProjects() { Dictionary <Guid, MsBuildProject> projects = new Dictionary <Guid, MsBuildProject>(); var projectCollection = new ProjectCollection(); foreach (var proj in this.SolutionFile.ProjectsInOrder) { var loadedProj = new MsBuildProject(new Project(proj.AbsolutePath, null, null, projectCollection), this.fileSystem); projects.Add(Guid.Parse(proj.ProjectGuid), loadedProj); } this.Projects = new ReadOnlyDictionary <Guid, MsBuildProject>(projects); }
protected string GetProjectRelativePath(CodeFileLocation location, MsBuildProject msBuildProject) { if (location is WorkspaceCodeFileLocation) { var wLocation = location as WorkspaceCodeFileLocation; if (!string.IsNullOrEmpty(wLocation.DocumentPath?.DocumentName)) { return(this.fileSystem.Path.Combine(string.Join(this.fileSystem.Path.DirectorySeparatorChar.ToString(), wLocation.DocumentPath.ProjectFolders), wLocation.DocumentPath.DocumentName)); } } else { return(PathMaskHelper.GetRelativePath(msBuildProject.FullPath, location.FilePath, this.fileSystem)); } return(null); }
public MsBuildItem(ProjectItem projectItem, MsBuildProject project) { this.Item = projectItem; this.project = project; }