public virtual Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
 {
     return(Task.FromException <SolutionItem> (new NotSupportedException()));
 }
Example #2
0
 public void ConvertToFormat(MSBuildFileFormat format)
 {
     SolutionExtension.OnSetFormat(format);
 }
        public override SolutionEntityItem LoadSolutionItem(IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid)
        {
            MSBuildProjectHandler handler = CreateHandler <MSBuildProjectHandler> (fileName, itemGuid);

            handler.SetCustomResourceHandler(GetResourceHandler());
            return(handler.Load(monitor, fileName, expectedFormat, language, null));
        }
        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);
            }
        }
 internal protected virtual void OnSetFormat(MSBuildFileFormat format)
 {
     next.OnSetFormat(format);
 }
 internal protected virtual bool OnGetSupportsFormat(MSBuildFileFormat format)
 {
     return(OnGetSupportsFormat(format));
 }
Example #7
0
        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);
        }
Example #8
0
 public override Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
 {
     return(Task <SolutionItem> .Factory.StartNew(delegate {
         CompiledAssemblyProject p = new CompiledAssemblyProject();
         p.LoadFrom(fileName);
         return p;
     }));
 }
 public override SolutionEntityItem LoadSolutionItem(IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid)
 {
     return(DubFileManager.Instance.LoadProject(fileName, Ide.IdeApp.Workspace.GetAllSolutions() [0], monitor));
 }
        public override Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
        {
            CompiledAssemblyProject p = new CompiledAssemblyProject();

            p.LoadFrom(fileName);
            return(Task.FromResult <SolutionItem> (p));
        }
Example #11
0
 public override Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
 {
     return(Task.Run(() => {
         foreach (var f in MSBuildFileFormat.GetSupportedFormats())
         {
             if (f.CanReadFile(fileName, typeof(SolutionItem)))
             {
                 return MSBuildProjectService.LoadItem(monitor, fileName, f, typeGuid, itemGuid, ctx);
             }
         }
         throw new NotSupportedException();
     }));
 }
Example #12
0
        public static async Task TestLoadSaveSolutionFolders(MSBuildFileFormat fileFormat)
        {
            List <string> ids = new List <string> ();

            Solution sol = new Solution();

            sol.ConvertToFormat(fileFormat);
            string dir = Util.CreateTmpDir("solution-folders");

            sol.FileName = Path.Combine(dir, "TestSolutionFolders");
            sol.Name     = "TheSolution";

            var p1 = Services.ProjectService.CreateDotNetProject("C#");

            p1.FileName = Path.Combine(dir, "p1");
            sol.RootFolder.Items.Add(p1);
            string idp1 = p1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp1));
            Assert.IsFalse(ids.Contains(idp1));
            ids.Add(idp1);

            SolutionFolder f1 = new SolutionFolder();

            f1.Name = "f1";
            sol.RootFolder.Items.Add(f1);
            string idf1 = f1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf1));
            Assert.IsFalse(ids.Contains(idf1));
            ids.Add(idf1);

            var p2 = Services.ProjectService.CreateDotNetProject("C#");

            p2.FileName = Path.Combine(dir, "p2");
            f1.Items.Add(p2);
            string idp2 = p2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp2));
            Assert.IsFalse(ids.Contains(idp2));
            ids.Add(idp2);

            SolutionFolder f2 = new SolutionFolder();

            f2.Name = "f2";
            f1.Items.Add(f2);
            string idf2 = f2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf2));
            Assert.IsFalse(ids.Contains(idf2));
            ids.Add(idf2);

            var p3 = Services.ProjectService.CreateDotNetProject("C#");

            p3.FileName = Path.Combine(dir, "p3");
            f2.Items.Add(p3);
            string idp3 = p3.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp3));
            Assert.IsFalse(ids.Contains(idp3));
            ids.Add(idp3);

            var p4 = Services.ProjectService.CreateDotNetProject("C#");

            p4.FileName = Path.Combine(dir, "p4");
            f2.Items.Add(p4);
            string idp4 = p4.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp4));
            Assert.IsFalse(ids.Contains(idp4));
            ids.Add(idp4);

            await sol.SaveAsync(Util.GetMonitor());

            Solution sol2 = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName);

            Assert.AreEqual(4, sol2.Items.Count);
            Assert.AreEqual(2, sol2.RootFolder.Items.Count);
            Assert.AreEqual("MonoDevelop.CSharp.Project.CSharpProject", sol2.RootFolder.Items[0].GetType().FullName);
            Assert.AreEqual(typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType());
            Assert.AreEqual("p1", sol2.RootFolder.Items [0].Name);
            Assert.AreEqual("f1", sol2.RootFolder.Items [1].Name);
            Assert.AreEqual(idp1, sol2.RootFolder.Items [0].ItemId, "idp1");
            Assert.AreEqual(idf1, sol2.RootFolder.Items [1].ItemId, "idf1");

            f1 = (SolutionFolder)sol2.RootFolder.Items [1];
            Assert.AreEqual(2, f1.Items.Count);
            Assert.AreEqual("MonoDevelop.CSharp.Project.CSharpProject", f1.Items [0].GetType().FullName);
            Assert.AreEqual(typeof(SolutionFolder), f1.Items [1].GetType());
            Assert.AreEqual("p2", f1.Items [0].Name);
            Assert.AreEqual("f2", f1.Items [1].Name);
            Assert.AreEqual(idp2, f1.Items [0].ItemId, "idp2");
            Assert.AreEqual(idf2, f1.Items [1].ItemId, "idf2");

            f2 = (SolutionFolder)f1.Items [1];
            Assert.AreEqual(2, f2.Items.Count);
            Assert.AreEqual("MonoDevelop.CSharp.Project.CSharpProject", f2.Items [0].GetType().FullName);
            Assert.AreEqual("MonoDevelop.CSharp.Project.CSharpProject", f2.Items [1].GetType().FullName);
            Assert.AreEqual("p3", f2.Items [0].Name);
            Assert.AreEqual("p4", f2.Items [1].Name);
            Assert.AreEqual(idp3, f2.Items [0].ItemId, "idp4");
            Assert.AreEqual(idp4, f2.Items [1].ItemId, "idp4");

            sol.Dispose();
        }
Example #13
0
 public override Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
 {
     return(Task.FromResult((SolutionItem)ReadFile(fileName, false, monitor)));
 }
Example #14
0
 public bool SupportsFormat(MSBuildFileFormat format)
 {
     return(true);
 }
Example #15
0
 public Task <SolutionItem> ReadSolutionItem(ProgressMonitor monitor, string file, MSBuildFileFormat format, string typeGuid = null, string itemGuid = null, SolutionLoadContext ctx = null)
 {
     return(Runtime.RunInMainThread(async delegate {
         if (!File.Exists(file))
         {
             throw new IOException(GettextCatalog.GetString("File not found: {0}", file));
         }
         file = Path.GetFullPath(file);
         var metadata = GetReadSolutionItemMetadata(file, typeGuid, itemGuid);
         using (Counters.ReadSolutionItem.BeginTiming("Read project " + file, metadata)) {
             file = GetTargetFile(file);
             var r = GetObjectReaderForFile(file, typeof(SolutionItem));
             if (r == null)
             {
                 throw new UnknownSolutionItemTypeException();
             }
             SolutionItem loadedItem = await r.LoadSolutionItem(monitor, ctx, file, format, typeGuid, itemGuid);
             if (loadedItem != null)
             {
                 loadedItem.NeedsReload = false;
                 UpdateReadSolutionItemMetadata(metadata, loadedItem);
             }
             return loadedItem;
         }
     }));
 }
Example #16
0
 bool OnGetSupportsFormat(MSBuildFileFormat format)
 {
     return(GetAllItems <SolutionItem> ().All(p => p.SupportsFormat(format)));
 }
Example #17
0
 public Task <string> Export(ProgressMonitor monitor, string rootSourceFile, string targetPath, MSBuildFileFormat format)
 {
     rootSourceFile = GetTargetFile(rootSourceFile);
     return(Export(monitor, rootSourceFile, null, targetPath, format));
 }
Example #18
0
        public override Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
        {
            return(Task.Run(() => {
                if (CanRead(fileName, typeof(SolutionItem)))
                {
                    DotNetCoreSdk.EnsureInitialized();
                    return MSBuildProjectService.LoadItem(monitor, fileName, MSBuildFileFormat.VS2012, typeGuid, itemGuid, ctx);
                }

                throw new NotSupportedException();
            }));
        }
Example #19
0
        public async Task <string> Export(ProgressMonitor monitor, string rootSourceFile, string[] includedChildIds, string targetPath, MSBuildFileFormat format)
        {
            IMSBuildFileObject obj = null;

            if (IsWorkspaceItemFile(rootSourceFile))
            {
                obj = (await ReadWorkspaceItem(monitor, rootSourceFile)) as IMSBuildFileObject;
            }
            else if (IsSolutionItemFile(rootSourceFile))
            {
                obj = await ReadSolutionItem(monitor, rootSourceFile);
            }
            if (obj == null)
            {
                throw new InvalidOperationException("File is not a solution or project.");
            }
            using (obj) {
                return(await Export(monitor, obj, includedChildIds, targetPath, format));
            }
        }
 internal protected virtual void OnSetFormat(MSBuildFileFormat value)
 {
     next.OnSetFormat(value);
 }
Example #21
0
        async Task <string> Export(ProgressMonitor monitor, IMSBuildFileObject obj, string[] includedChildIds, string targetPath, MSBuildFileFormat format)
        {
            string rootSourceFile = obj.FileName;
            string sourcePath     = Path.GetFullPath(Path.GetDirectoryName(rootSourceFile));

            targetPath = Path.GetFullPath(targetPath);

            if (sourcePath != targetPath)
            {
                if (!CopyFiles(monitor, obj, obj.GetItemFiles(true), targetPath, true))
                {
                    return(null);
                }

                string newFile = Path.Combine(targetPath, Path.GetFileName(rootSourceFile));
                if (IsWorkspaceItemFile(rootSourceFile))
                {
                    obj = (Solution) await ReadWorkspaceItem(monitor, newFile);
                }
                else
                {
                    obj = await ReadSolutionItem(monitor, newFile);
                }

                using (obj) {
                    var oldFiles = obj.GetItemFiles(true).ToList();
                    ExcludeEntries(obj, includedChildIds);
                    if (format != null)
                    {
                        obj.ConvertToFormat(format);
                    }
                    await obj.SaveAsync(monitor);

                    var newFiles           = obj.GetItemFiles(true);
                    var resolvedTargetPath = new FilePath(targetPath).ResolveLinks().FullPath;

                    foreach (FilePath f in newFiles)
                    {
                        if (!f.IsChildPathOf(resolvedTargetPath))
                        {
                            if (obj is Solution)
                            {
                                monitor.ReportError(GettextCatalog.GetString("The solution '{0}' is referencing the file '{1}' which is located outside the root solution directory.", obj.Name, f.FileName), null);
                            }
                            else
                            {
                                monitor.ReportError(GettextCatalog.GetString("The project '{0}' is referencing the file '{1}' which is located outside the project directory.", obj.Name, f.FileName), null);
                            }
                        }
                        oldFiles.Remove(f);
                    }

                    // Remove old files
                    foreach (FilePath file in oldFiles)
                    {
                        if (File.Exists(file))
                        {
                            File.Delete(file);

                            // Exclude empty directories
                            FilePath dir = file.ParentDirectory;
                            if (!Directory.EnumerateFileSystemEntries(dir).Any())
                            {
                                try {
                                    Directory.Delete(dir);
                                } catch (Exception ex) {
                                    monitor.ReportError(null, ex);
                                }
                            }
                        }
                    }
                    return(obj.FileName);
                }
            }
            else
            {
                using (obj) {
                    ExcludeEntries(obj, includedChildIds);
                    if (format != null)
                    {
                        obj.ConvertToFormat(format);
                    }
                    await obj.SaveAsync(monitor);

                    return(obj.FileName);
                }
            }
        }
Example #22
0
 public override SolutionEntityItem LoadSolutionItem(IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid)
 {
     throw new NotImplementedException();
 }
Example #23
0
 internal protected override bool OnGetSupportsFormat(MSBuildFileFormat format)
 {
     return(Solution.OnGetSupportsFormat(format));
 }
        public override SolutionEntityItem LoadSolutionItem(IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid)
        {
            MSBuildProjectHandler handler = CreateHandler <MSBuildProjectHandler> (fileName, itemGuid);

            return(handler.Load(monitor, fileName, expectedFormat, null, ItemType));
        }
Example #25
0
 internal protected override void OnSetFormat(MSBuildFileFormat value)
 {
     Solution.OnSetFormat(value);
 }
Example #26
0
 public abstract SolutionEntityItem LoadSolutionItem(IProgressMonitor monitor, string fileName, MSBuildFileFormat expectedFormat, string itemGuid);
Example #27
0
        public override async Task <SolutionItem> LoadSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName, MSBuildFileFormat expectedFormat, string typeGuid, string itemGuid)
        {
            if (CanRead(fileName, typeof(SolutionItem)))
            {
                return(await MSBuildProjectService.LoadItem(monitor, fileName, MSBuildFileFormat.VS2012, typeGuid, itemGuid, ctx));
            }

            throw new NotSupportedException();
        }