private ProjectFileBase OpenProject(string filename, bool recurse) { ProjectFileBase project = null; if (filename.EndsWith(".wixproj")) { project = OpenWixProject(filename); } else if (filename.EndsWith(".csproj")) { project = OpenVisualStudioCsProject(filename); } else if (filename.EndsWith(".vcxproj")) { project = OpenVisualStudioVCxProject(filename); } else if (filename.EndsWith(".proj")) { project = OpenMsBuildProject(filename); } else if (filename.EndsWith(".sln")) { project = VisualStudioSolution = OpenVisualStudioSolution(filename); } else { base.HandleException(this, new Exception($"Un-registered file extension {System.IO.Path.GetExtension(filename)}")); } if (project != null) { Terminal.WriteLine($"{project.FileType} opened: {project.ProjectPath}"); Terminal.Write(project.Results(Verbose)); if (project.ImportFailed) { FileOpenFailed(project.FileType, filename); } MissingProjects.AddRange(project.MissingProjects); MissingFiles.AddRange(project.MissingFiles); if (recurse) { foreach (var nested in project.Projects) { OpenProject(nested.Path, recurse); } } } else { HandleException(this, new Exception($"File open failed! [{filename}]")); } return(project); }
public override IEnumerable <string> Compare(ProjectFileBase project, bool verbose) { var csproject = project as VisualStudioCsProject; if (csproject == null) { return(base.Compare(project, verbose)); } return(CsProjComparison.Compare(this, csproject, verbose)); }
private void Compare(ProjectFileBase baseProject) { if (baseProject != null) { var dialog = new OpenFileDialog { Filter = $"{MsBuildProject.FileFilter}|{WixProject.FileFilter}" }; if (dialog.ShowDialog() == true) { var filename = dialog.FileName; var project = OpenProject(filename, false); if (project != null) { var result = baseProject.Compare(project, Verbose); Terminal.Write(result); } } } }
public List <ProjectFile> SourceFiles(ProjectFileBase project) { var files = ExtractSourceFiles(Compile, ResourceType.SourceFile, project); files.AddRange(ExtractSourceFiles(EmbeddedResource, ResourceType.EmbeddedResource, project)); files.AddRange(ExtractSourceFiles(Resource, ResourceType.Resource, project)); files.AddRange(ExtractSourceFiles(ProjectReference, ResourceType.ProjectReference, project)); files.AddRange(ExtractSourceFiles(Reference, ResourceType.Reference, project)); if (Content != null) { files.AddRange(ExtractSourceFiles(new [] { Content }, ResourceType.Content, project)); } if (ApplicationDefinition != null) { files.AddRange(ExtractSourceFiles(new[] { ApplicationDefinition }, ResourceType.ApplicationDefinition, project)); } files.AddRange(ExtractSourceFiles(Page, ResourceType.Page, project)); files.AddRange(ExtractSourceFiles(None, ResourceType.Unknown, project)); return(files); }
public IProjectFile OpenFile(string fileSystemPath) { if (!File.Exists(fileSystemPath)) { return(null); } IProjectFile file = _solution == null ? null : _solution.GetProjectFile(fileSystemPath); if (file == null) { file = solutionExplorer.FindFile(fileSystemPath); if (file == null) { file = _nonProjectFiles.FirstOrDefault(x => x.FileSystemPath.Equals(fileSystemPath, StringComparison.OrdinalIgnoreCase)); if (file == null) { file = ProjectFileBase.CreatFile(fileSystemPath, false); _nonProjectFiles.Add(file); } } } OpenFile(file); return(file); }
private static List <ProjectFile> ExtractSourceFiles(IEnumerable <ProjectItemGroup> items, ResourceType resourceType, ProjectFileBase project) { var files = new List <ProjectFile>(); if (items == null) { return(files); } foreach (var item in items) { var resource = ProjectFile.CreateIfValid(item, resourceType, project); if (resource != null) { files.Add(resource); } else { } } return(files); }
/// <summary> /// Merges the specified project into the current project. /// </summary> /// <param name="project">The project whose contents are to be merged into the current project.</param> /// <param name="verbose">if set to <c>true</c> [verbose].</param> /// <returns>IEnumerable<System.String>.</returns> public override IEnumerable <string> Merge(ProjectFileBase project, IEnumerable <string> omit, bool verbose) { var csSourceProject = project as VisualStudioCsProject; if (csSourceProject == null) { return(base.Merge(project, omit, verbose)); } var result = new List <string>(); if (verbose) { result.AddRange(new string[] { $"Merge {this.FileType}s", $"\t{ProjectFilename}", $"\t{project.ProjectFilename}" }); } var sourceToAdd = new List <ProjectFile>(); var sourceToSkip = new List <ProjectFile>(); var filteredSource = SourceFiles.Where((f) => f.ResourceType == ResourceType.SourceFile).ToList(); var sourcesToOmit = filteredSource.Select((f) => Path.GetFileName(f.FileName)).ToList(); if (omit != null) { sourcesToOmit.AddRange(omit); } var csFilteredSource = csSourceProject.SourceFiles.Where((s) => s.ResourceType == ResourceType.SourceFile).ToList(); foreach (var csSource in csFilteredSource) { var csFilename = Path.GetFileName(csSource.FileName); if (!sourcesToOmit.Contains(csFilename)) { sourceToAdd.Add(csSource); } else { sourceToSkip.Add(csSource); } } if (verbose || sourceToSkip.Count > 0) { result.Add($"Merging {ResourceType.SourceFile}s {Path.GetFileName(project.ProjectFilename)}=>{Path.GetFileName(this.ProjectFilename)} {sourceToAdd.Count}/{csFilteredSource.Count} files."); } var folder = Path.GetFileNameWithoutExtension(csSourceProject.ProjectFilename); foreach (var item in Items) { var itemGroup = item as ItemGroup; if (itemGroup != null && itemGroup.Compile != null) { var compile = new List <Compile>(itemGroup.Compile); foreach (var source in sourceToAdd) { compile.Add(source.ToCompile(this.ProjectPath, folder)); } itemGroup.Compile = compile.ToArray(); } } if (verbose) { foreach (var source in sourceToAdd) { result.Add($"\tAdd:\t{source}"); } } foreach (var source in sourceToSkip) { result.Add($"\tSkip:\t{source}"); } return(result); }