public override PackageBuilder[] CreateDefaultBuilders() { List <PackageBuilder> list = new List <PackageBuilder> (); IMSBuildFileObject root = RootSolutionItem is SolutionItem ? (IMSBuildFileObject)RootSolutionItem : (IMSBuildFileObject)RootSolutionItem.ParentSolution; foreach (MSBuildFileFormat format in MSBuildFileFormat.GetSupportedFormats(root)) { SourcesZipPackageBuilder pb = (SourcesZipPackageBuilder)Clone(); pb.FileFormat = format; // The suffix for the archive will be the extension of the file format. // If there is no extension, use the whole file name. string fname = format.GetValidFormatName(RootSolutionItem, RootSolutionItem.ParentSolution.FileName); string suffix = Path.GetExtension(fname); if (suffix.Length > 0) { suffix = suffix.Substring(1).ToLower(); // Remove the initial dot } else { suffix = Path.GetFileNameWithoutExtension(suffix).ToLower(); } // Change the name in the target file string ext = DeployService.GetArchiveExtension(pb.TargetFile); string fn = TargetFile.Substring(0, TargetFile.Length - ext.Length); pb.TargetFile = fn + "-" + suffix + ext; list.Add(pb); } return(list.ToArray()); }
public SelectFileFormatDialog(IMSBuildFileObject item) { this.Build(); string warning = ""; foreach (string msg in item.FileFormat.GetCompatibilityWarnings(item)) { warning += msg + "\n"; } if (warning.Length > 0) { warning = warning.Substring(0, warning.Length - 1); } labelWarnings.Text = warning; labelMessage.Text = string.Format(labelMessage.Text, item.Name); labelCurrentFormat.Text = item.FileFormat.Name; foreach (MSBuildFileFormat format in MSBuildFileFormat.GetSupportedFormats(item)) { comboNewFormat.AppendText(format.Name); formats.Add(format); } comboNewFormat.Active = 0; }
public SourcesZipEditorWidget(PackageBuilder target, MSBuildFileFormat selectedFormat) { this.Build(); this.target = (SourcesZipPackageBuilder)target; loading = true; if (target.RootSolutionItem is SolutionFolder) { formats = MSBuildFileFormat.GetSupportedFormats(target.Solution).ToArray(); } else { formats = MSBuildFileFormat.GetSupportedFormats((SolutionItem)target.RootSolutionItem).ToArray(); } if (selectedFormat == null) { selectedFormat = this.target.FileFormat; } if (selectedFormat == null) { selectedFormat = formats [0]; } int sel = 0; for (int n = 0; n < formats.Length; n++) { comboFormat.AppendText(formats[n].Name); if (formats[n].Name == selectedFormat.Name) { sel = n; } } comboFormat.Active = sel; this.target.FileFormat = formats [sel]; string[] archiveFormats = DeployService.SupportedArchiveFormats; int zel = 1; for (int n = 0; n < archiveFormats.Length; n++) { comboZip.AppendText(archiveFormats [n]); if (this.target.TargetFile.EndsWith(archiveFormats [n])) { zel = n; } } if (!string.IsNullOrEmpty(this.target.TargetFile)) { string ext = archiveFormats [zel]; folderEntry.Path = System.IO.Path.GetDirectoryName(this.target.TargetFile); entryZip.Text = System.IO.Path.GetFileName(this.target.TargetFile.Substring(0, this.target.TargetFile.Length - ext.Length)); comboZip.Active = zel; } loading = false; }
public override bool CanRead(FilePath file, Type expectedType) { foreach (var f in MSBuildFileFormat.GetSupportedFormats()) { if (f.CanReadFile(file, expectedType)) { return(true); } } return(false); }
public override async Task <WorkspaceItem> LoadWorkspaceItem(ProgressMonitor monitor, string fileName) { foreach (var f in MSBuildFileFormat.GetSupportedFormats()) { if (f.CanReadFile(fileName, typeof(WorkspaceItem))) { return((WorkspaceItem)await f.ReadFile(fileName, typeof(WorkspaceItem), monitor).ConfigureAwait(false)); } } throw new NotSupportedException(); }
public override async Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid) { foreach (var f in MSBuildFileFormat.GetSupportedFormats()) { if (f.CanReadFile(fileName, typeof(SolutionItem))) { return(await MSBuildProjectService.LoadItem(monitor, fileName, f, typeGuid, itemGuid, ctx).ConfigureAwait(false)); } } throw new NotSupportedException(); }
public ExportSolutionDialog(IMSBuildFileObject item, MSBuildFileFormat selectedFormat) { this.Build(); labelNewFormat.Text = selectedFormat.ProductDescription; formats = MSBuildFileFormat.GetSupportedFormats(item).ToArray(); foreach (var format in formats) { comboFormat.AppendText(format.ProductDescription); } int sel = Array.IndexOf(formats, selectedFormat); if (sel == -1) { sel = 0; } comboFormat.Active = sel; if (formats.Length < 2) { table.Remove(newFormatLabel); newFormatLabel.Destroy(); newFormatLabel = null; table.Remove(comboFormat); comboFormat.Destroy(); comboFormat = null; } //auto height folderEntry.WidthRequest = 380; Resize(1, 1); folderEntry.Path = item.ItemDirectory; UpdateControls(); }
public async Task <int> Run(string[] arguments) { if (arguments.Length == 0 || arguments [0] == "--help") { Console.WriteLine(""); Console.WriteLine("Project Export Tool"); Console.WriteLine("Usage: mdtool project-export <source-project-file> [-d:dest-path] [-f:format-name]"); Console.WriteLine(""); Console.WriteLine("Options"); Console.WriteLine(" -d:<dest-path> Directory where the project will be exported."); Console.WriteLine(" -f:\"<format-name>\" Format to which export the project or solution."); Console.WriteLine(" -l Show a list of all allowed target formats."); Console.WriteLine(" -p:<project-name> When exporting a solution, name of a project to be"); Console.WriteLine(" included in the export. It can be specified multiple"); Console.WriteLine(" times."); Console.WriteLine(""); Console.WriteLine(" The format name is optional. A list of allowed file formats will be"); Console.WriteLine(" shown if none is provided."); Console.WriteLine(""); return(0); } string projectFile = null; string destPath = null; string formatName = null; bool formatList = false; List <string> projects = new List <string> (); string[] itemsToExport = null; foreach (string s in arguments) { if (s.StartsWith("-d:")) { destPath = s.Substring(3); } else if (s.StartsWith("-f:")) { formatName = s.Substring(3); } else if (s.StartsWith("-p:")) { projects.Add(s.Substring(3)); } else if (s == "-l") { formatList = true; } else if (projectFile != null) { Console.WriteLine("Only one project can be converted at a time."); return(1); } else { projectFile = s; } } if (projectFile == null) { Console.WriteLine("Project or solution file name not provided."); return(1); } projectFile = FileService.GetFullPath(projectFile); if (!File.Exists(projectFile)) { Console.WriteLine("File {0} not found.", projectFile); return(1); } ConsoleProgressMonitor monitor = new ConsoleProgressMonitor(); monitor.IgnoreLogMessages = true; object item; if (Services.ProjectService.IsWorkspaceItemFile(projectFile)) { item = await Services.ProjectService.ReadWorkspaceItem(monitor, projectFile); if (projects.Count > 0) { Solution sol = item as Solution; if (sol == null) { Console.WriteLine("The -p option can only be used when exporting a solution."); return(1); } for (int n = 0; n < projects.Count; n++) { string pname = projects [n]; if (pname.Length == 0) { Console.WriteLine("Project name not specified in -p option."); return(1); } Project p = sol.FindProjectByName(pname); if (p == null) { Console.WriteLine("Project '" + pname + "' not found in solution."); return(1); } projects[n] = p.ItemId; } itemsToExport = projects.ToArray(); } } else { if (projects.Count > 0) { Console.WriteLine("The -p option can't be used when exporting a single project"); return(1); } item = await Services.ProjectService.ReadSolutionItem(monitor, projectFile); } var formats = MSBuildFileFormat.GetSupportedFormats().ToArray(); if (formats.Length == 0) { Console.WriteLine("Can't convert file to any format: " + projectFile); return(1); } MSBuildFileFormat format = null; if (formatName == null || formatList) { Console.WriteLine(); Console.WriteLine("Target formats:"); for (int n = 0; n < formats.Length; n++) { Console.WriteLine(" {0}. {1}", n + 1, formats [n].Name); } Console.WriteLine(); if (formatList) { return(0); } int op = 0; do { Console.Write("Convert to format: "); string s = Console.ReadLine(); if (s.Length == 0) { return(1); } if (int.TryParse(s, out op)) { if (op > 0 && op <= formats.Length) { break; } } } while (true); format = formats [op - 1]; } else { foreach (var f in formats) { if (f.Name == formatName) { format = f; } } if (format == null) { Console.WriteLine("Unknown file format: " + formatName); return(1); } } if (destPath == null) { destPath = Path.GetDirectoryName(projectFile); } destPath = FileService.GetFullPath(destPath); string ofile = await Services.ProjectService.Export(monitor, projectFile, itemsToExport, destPath, format); if (ofile != null) { Console.WriteLine("Saved file: " + ofile); return(0); } else { Console.WriteLine("Project export failed."); return(1); } }
public WorkspaceItemCreatedInformation CreateEntry(ProjectCreateInformation projectCreateInformation, string defaultLanguage) { WorkspaceItem workspaceItem = null; if (string.IsNullOrEmpty(type)) { workspaceItem = new Solution(); } else { Type workspaceItemType = addin.GetType(type, false); if (workspaceItemType != null) { workspaceItem = Activator.CreateInstance(workspaceItemType) as WorkspaceItem; } if (workspaceItem == null) { MessageService.ShowError(GettextCatalog.GetString("Can't create solution with type: {0}", type)); return(null); } } var substitution = new string[, ] { { "ProjectName", projectCreateInformation.SolutionName } }; workspaceItem.Name = StringParserService.Parse(name, substitution); string newStartupProjectName = startupProject; if (newStartupProjectName != null) { newStartupProjectName = StringParserService.Parse(startupProject, substitution); } workspaceItem.SetLocation(projectCreateInformation.SolutionPath, workspaceItem.Name); ProjectCreateInformation localProjectCI; if (!string.IsNullOrEmpty(directory) && directory != ".") { localProjectCI = new ProjectCreateInformation(projectCreateInformation); localProjectCI.SolutionPath = Path.Combine(localProjectCI.SolutionPath, directory); localProjectCI.ProjectBasePath = Path.Combine(localProjectCI.ProjectBasePath, directory); if (!Directory.Exists(localProjectCI.SolutionPath)) { Directory.CreateDirectory(localProjectCI.SolutionPath); } if (!Directory.Exists(localProjectCI.ProjectBasePath)) { Directory.CreateDirectory(localProjectCI.ProjectBasePath); } } else { localProjectCI = projectCreateInformation; } var workspaceItemCreatedInfo = new WorkspaceItemCreatedInformation(workspaceItem); Solution solution = workspaceItem as Solution; if (solution != null) { for (int i = 0; i < entryDescriptors.Count; i++) { ProjectCreateInformation entryProjectCI; var entry = entryDescriptors[i] as ICustomProjectCIEntry; if (entry != null) { entryProjectCI = entry.CreateProjectCI(localProjectCI); entryProjectCI = new ProjectTemplateCreateInformation(entryProjectCI, localProjectCI.ProjectName); } else { entryProjectCI = localProjectCI; } var solutionItemDesc = entryDescriptors[i]; SolutionItem info = solutionItemDesc.CreateItem(entryProjectCI, defaultLanguage); if (info == null) { continue; } solutionItemDesc.InitializeItem(solution.RootFolder, entryProjectCI, defaultLanguage, info); IConfigurationTarget configurationTarget = info as IConfigurationTarget; if (configurationTarget != null) { foreach (ItemConfiguration configuration in configurationTarget.Configurations) { bool flag = false; foreach (SolutionConfiguration solutionCollection in solution.Configurations) { if (solutionCollection.Id == configuration.Id) { flag = true; } } if (!flag) { solution.AddConfiguration(configuration.Id, true); } } } if ((info is Project) && (solutionItemDesc is ProjectDescriptor)) { workspaceItemCreatedInfo.AddPackageReferenceForCreatedProject((Project)info, (ProjectDescriptor)solutionItemDesc, projectCreateInformation); } solution.RootFolder.Items.Add(info); if (newStartupProjectName == info.Name) { solution.StartupItem = info; } } } var sol = workspaceItem as Solution; if (sol != null && !sol.SupportsFormat(sol.FileFormat)) { // The default format can't write solutions of this type. Find a compatible format. var f = MSBuildFileFormat.GetSupportedFormats().First(ff => ff.CanWriteFile(sol)); sol.ConvertToFormat(f); } return(workspaceItemCreatedInfo); }