Exemple #1
0
        public void ProjectReferenceWithSpace()
        {
            string   solFile = Util.GetSampleProject("project-ref-with-spaces", "project-ref-with-spaces.sln");
            Solution sol     = Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile) as Solution;

            Assert.IsNotNull(sol);
            Assert.AreEqual(2, sol.Items.Count);

            DotNetProject p = sol.FindProjectByName("project-ref-with-spaces") as DotNetProject;

            Assert.IsNotNull(p);

            Assert.AreEqual(1, p.References.Count);
            Assert.AreEqual("some - library", p.References[0].Reference);
        }
        public async Task LoadGenericProject()
        {
            string solFile = Util.GetSampleProject("generic-project", "generic-project.sln");

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

            var p = sol.FindProjectByName("GenericProject");

            Assert.IsInstanceOf <GenericProject> (p);

            var pl = (GenericProject)p;

            Assert.AreEqual("Default", pl.Configurations [0].Name);
            sol.Dispose();
        }
Exemple #3
0
        public async Task AddingRemovingAndThenAddingReferenceToPortableLibrarySavesReferenceToFile()
        {
            string solFile = Util.GetSampleProject("portable-library", "portable-library.sln");

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

            var p = sol.FindProjectByName("PortableLibrary") as DotNetProject;

            Assert.AreEqual(0, p.References.Count);

            // Add System.Xml reference.
            p.References.Add(ProjectReference.CreateAssemblyReference("System.Xml"));
            await p.SaveAsync(Util.GetMonitor());

            Assert.AreEqual(1, p.References.Count);

            // Remove System.Xml reference so no references remain.
            p.References.RemoveAt(0);
            await p.SaveAsync(Util.GetMonitor());

            Assert.AreEqual(0, p.References.Count);

            // Add System.Xml reference again.
            p.References.Add(ProjectReference.CreateAssemblyReference("System.Xml"));
            await p.SaveAsync(Util.GetMonitor());

            Assert.AreEqual(1, p.References.Count);

            // Ensure the references are saved to the file.
            sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            p = sol.FindProjectByName("PortableLibrary") as DotNetProject;

            Assert.AreEqual(1, p.References.Count);
            Assert.AreEqual("System.Xml", p.References[0].Include);
        }
        public async Task LoadPortableLibrary()
        {
            string solFile = Util.GetSampleProject("portable-library", "portable-library.sln");

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

            var p = sol.FindProjectByName("PortableLibrary");

            Assert.IsInstanceOf <DotNetProject> (p);

            var pl = (DotNetProject)p;

            Assert.AreEqual(".NETPortable", pl.GetDefaultTargetFrameworkId().Identifier);

            sol.Dispose();
        }
Exemple #5
0
 internal void ResolveObjects(Solution sol)
 {
     if (ItemId != null)
     {
         SolutionItem = sol.GetSolutionItem(ItemId) as SolutionItem;
         if (SolutionItem == null)
         {
             SolutionItem = sol.FindProjectByName(ItemName) as SolutionItem;
         }
         if (SolutionItem != null && ConfigurationId != null)
         {
             RunConfiguration = SolutionItem.GetRunConfigurations().FirstOrDefault(c => c.Id == ConfigurationId);
         }
         ItemId          = null;
         ConfigurationId = null;
     }
 }
        public async Task ProjItemsFileNameNotMatchingShproj_Bug20571()
        {
            string   solFile = Util.GetSampleProject("SharedProjectTestBug20571", "SharedProjectTest.sln");
            Solution sol     = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            Assert.AreEqual(3, sol.GetAllProjects().Count());

            var pc1 = (DotNetProject)sol.FindProjectByName("Console1");

            Assert.IsNotNull(pc1);

            var pc2 = (DotNetProject)sol.FindProjectByName("Console2");

            Assert.IsNotNull(pc2);

            var pcs = (SharedAssetsProject)sol.FindProjectByName("Shared");

            Assert.IsNotNull(pcs);

            Assert.IsTrue(pc1.References.Any(r => r.Reference == "Shared"));

            var sharedFile = pcs.ItemDirectory.Combine("MyClass.cs");

            Assert.IsTrue(pc1.Files.GetFile(sharedFile) != null);
            Assert.IsTrue(pc2.Files.GetFile(sharedFile) == null);
            Assert.IsTrue(pcs.Files.GetFile(sharedFile) != null);

            pc2.References.Add(ProjectReference.CreateProjectReference(pcs));
            Assert.IsTrue(pc2.Files.GetFile(sharedFile) != null);

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

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

            sol.Dispose();

            pc2 = (DotNetProject)sol2.FindProjectByName("Console2");
            Assert.IsNotNull(pc2);

            Assert.IsTrue(pc2.References.Any(r => r.Reference == "Shared"));

            Assert.IsTrue(pc2.Files.GetFile(sharedFile) != null);

            sol2.Dispose();
        }
 /// <summary>
 /// Resolves a project for a ReferenceType.Project reference type in a given solution.
 /// </summary>
 /// <returns>The project, or <c>null</c> if it couldn't be resolved.</returns>
 /// <param name="inSolution">The solution the project is in.</param>
 /// <exception cref="T:System.ArgumentNullException">Thrown if inSolution == null</exception>
 /// <exception cref="T:System.InvalidOperationException">Thrown if ReferenceType != ReferenceType.Project</exception>
 public Project ResolveProject(Solution inSolution)
 {
     if (inSolution == null)
     {
         throw new ArgumentNullException("inSolution");
     }
     if (ReferenceType != ReferenceType.Project)
     {
         throw new InvalidOperationException("ResolveProject is only definied for Project reference type.");
     }
     if (!string.IsNullOrEmpty(projectGuid))
     {
         var project = inSolution.GetSolutionItem(projectGuid) as Project;
         if (project != null)
         {
             return(project);
         }
     }
     return(inSolution.FindProjectByName(Reference));
 }
Exemple #8
0
        public void ModelQueries()
        {
            DotNetProject     it2, it3, it4;
            DummySolutionItem it1;
            string            someFile, someId;

            Workspace ws  = new Workspace();
            Workspace cws = new Workspace();

            ws.Items.Add(cws);

            Solution sol1 = new Solution();

            cws.Items.Add(sol1);
            sol1.RootFolder.Items.Add(it1 = new DummySolutionItem());
            sol1.RootFolder.Items.Add(it2 = new DotNetAssemblyProject("C#"));

            Solution sol2 = new Solution();

            cws.Items.Add(sol2);
            SolutionFolder f = new SolutionFolder();

            sol2.RootFolder.Items.Add(f);
            f.Items.Add(it3 = new DotNetAssemblyProject("C#"));
            f.Items.Add(it4 = new DotNetAssemblyProject("C#"));

            it3.Name     = "it3";
            it4.FileName = "/test/it4";
            someFile     = it4.FileName;
            someId       = it3.ItemId;
            Assert.IsFalse(string.IsNullOrEmpty(someId));

            Assert.AreEqual(2, sol1.Items.Count);
            Assert.IsTrue(sol1.Items.Contains(it1));
            Assert.IsTrue(sol1.Items.Contains(it2));

            Assert.AreEqual(2, sol2.Items.Count);
            Assert.IsTrue(sol2.Items.Contains(it3));
            Assert.IsTrue(sol2.Items.Contains(it4));

            ReadOnlyCollection <SolutionItem> its = ws.GetAllSolutionItems();

            Assert.AreEqual(7, its.Count);
            Assert.IsTrue(its.Contains(it1));
            Assert.IsTrue(its.Contains(it2));
            Assert.IsTrue(its.Contains(it3));
            Assert.IsTrue(its.Contains(it4));
            Assert.IsTrue(its.Contains(sol1.RootFolder));
            Assert.IsTrue(its.Contains(sol2.RootFolder));
            Assert.IsTrue(its.Contains(f));

            ReadOnlyCollection <DotNetProject> its2 = ws.GetAllSolutionItems <DotNetProject> ();

            Assert.AreEqual(3, its2.Count);
            Assert.IsTrue(its2.Contains(it2));
            Assert.IsTrue(its2.Contains(it3));
            Assert.IsTrue(its2.Contains(it4));

            ReadOnlyCollection <Project> its3 = ws.GetAllProjects();

            Assert.AreEqual(3, its3.Count);
            Assert.IsTrue(its3.Contains(it2));
            Assert.IsTrue(its3.Contains(it3));
            Assert.IsTrue(its3.Contains(it4));

            ReadOnlyCollection <Solution> its4 = ws.GetAllSolutions();

            Assert.AreEqual(2, its4.Count);
            Assert.IsTrue(its4.Contains(sol1));
            Assert.IsTrue(its4.Contains(sol2));

            ReadOnlyCollection <WorkspaceItem> its5 = ws.GetAllItems();

            Assert.AreEqual(4, its5.Count);
            Assert.IsTrue(its5.Contains(ws));
            Assert.IsTrue(its5.Contains(cws));
            Assert.IsTrue(its5.Contains(sol2));
            Assert.IsTrue(its5.Contains(sol2));

            ReadOnlyCollection <Workspace> its6 = ws.GetAllItems <Workspace> ();

            Assert.AreEqual(2, its6.Count);
            Assert.IsTrue(its6.Contains(ws));
            Assert.IsTrue(its6.Contains(cws));

            SolutionEntityItem fi = ws.FindSolutionItem(someFile);

            Assert.AreEqual(it4, fi);

            fi = ws.FindSolutionItem(someFile + ".wrong");
            Assert.IsNull(fi);

            SolutionItem si = sol2.GetSolutionItem(someId);

            Assert.AreEqual(it3, si);

            fi = sol2.FindSolutionItem(someFile);
            Assert.AreEqual(it4, fi);

            fi = sol2.FindProjectByName("it3");
            Assert.AreEqual(it3, fi);

            fi = sol2.FindProjectByName("it4");
            Assert.AreEqual(it4, fi);

            fi = sol2.FindProjectByName("it2");
            Assert.IsNull(fi);
        }
Exemple #9
0
        public async Task BuildingAndCleaning()
        {
            string solFile = Util.GetSampleProject("console-with-libs", "console-with-libs.sln");

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

            DotNetProject p    = (DotNetProject)sol.FindProjectByName("console-with-libs");
            DotNetProject lib1 = (DotNetProject)sol.FindProjectByName("library1");
            DotNetProject lib2 = (DotNetProject)sol.FindProjectByName("library2");

            SolutionFolder folder = new SolutionFolder();

            folder.Name = "subfolder";
            sol.RootFolder.Items.Add(folder);
            sol.RootFolder.Items.Remove(lib2);
            folder.Items.Add(lib2);

            Workspace ws = new Workspace();

            ws.FileName = Path.Combine(sol.BaseDirectory, "workspace");
            ws.Items.Add(sol);
            await ws.SaveAsync(Util.GetMonitor());

            // Build the project and the references

            BuildResult res = await ws.Build(Util.GetMonitor(), ConfigurationSelector.Default);

            Assert.AreEqual(0, res.ErrorCount);
            Assert.AreEqual(0, res.WarningCount);
            Assert.AreEqual(3, res.BuildCount);

            Assert.IsTrue(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsTrue(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Clean the workspace

            await ws.Clean(Util.GetMonitor(), ConfigurationSelector.Default);

            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Build the solution

            res = await ws.Build(Util.GetMonitor(), ConfigurationSelector.Default);

            Assert.AreEqual(0, res.ErrorCount);
            Assert.AreEqual(0, res.WarningCount);
            Assert.AreEqual(3, res.BuildCount);

            Assert.IsTrue(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsTrue(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Clean the solution

            await sol.Clean(Util.GetMonitor(), "Debug");

            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Build the solution folder

            res = await folder.Build(Util.GetMonitor(), (SolutionConfigurationSelector)"Debug");

            Assert.AreEqual(0, res.ErrorCount);
            Assert.AreEqual(0, res.WarningCount);
            Assert.AreEqual(1, res.BuildCount);

            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Clean the solution folder

            await folder.Clean(Util.GetMonitor(), (SolutionConfigurationSelector)"Debug");

            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));
            sol.Dispose();
        }
        public int Run(string[] arguments)
        {
            Console.WriteLine("MonoDevelop Build Tool");
            foreach (string s in arguments)
            {
                ReadArgument(s);
            }

            if (help)
            {
                Console.WriteLine("build [options] [build-file]");
                Console.WriteLine("-p --project:PROJECT  Name of the project to build.");
                Console.WriteLine("-t --target:TARGET    Name of the target: Build or Clean.");
                Console.WriteLine("-c --configuration:CONFIGURATION  Name of the solution configuration to build.");
                Console.WriteLine();
                Console.WriteLine("Supported targets:");
                Console.WriteLine("  {0}: build the project (the default target).", ProjectService.BuildTarget);
                Console.WriteLine("  {0}: clean the project.", ProjectService.CleanTarget);
                Console.WriteLine();
                return(0);
            }

            string solFile  = null;
            string itemFile = null;

            if (file == null)
            {
                string[] files = Directory.GetFiles(".");
                foreach (string f in files)
                {
                    if (Services.ProjectService.IsWorkspaceItemFile(f))
                    {
                        solFile = f;
                        break;
                    }
                    else if (itemFile == null && Services.ProjectService.IsSolutionItemFile(f))
                    {
                        itemFile = f;
                    }
                }
                if (solFile == null && itemFile == null)
                {
                    Console.WriteLine("Project file not found.");
                    return(1);
                }
            }
            else
            {
                if (Services.ProjectService.IsWorkspaceItemFile(file))
                {
                    solFile = file;
                }
                else if (Services.ProjectService.IsSolutionItemFile(file))
                {
                    itemFile = file;
                }
                else
                {
                    Console.WriteLine("File '{0}' is not a project or solution.", file);
                    return(1);
                }
            }

            ConsoleProgressMonitor monitor = new ConsoleProgressMonitor();

            IBuildTarget item;

            if (solFile != null)
            {
                item = Services.ProjectService.ReadWorkspaceItem(monitor, solFile);
            }
            else
            {
                item = Services.ProjectService.ReadSolutionItem(monitor, itemFile);
            }

            if (project != null)
            {
                Solution solution = item as Solution;
                item = null;

                if (solution != null)
                {
                    item = solution.FindProjectByName(project);
                }
                if (item == null)
                {
                    Console.WriteLine("The project '" + project + "' could not be found in " + file);
                    return(1);
                }
            }

            IConfigurationTarget configTarget = item as IConfigurationTarget;

            if (config == null && configTarget != null)
            {
                config = configTarget.DefaultConfigurationId;
            }

            ConfigurationSelector configuration;

            if (item is SolutionEntityItem)
            {
                configuration = new ItemConfigurationSelector(config);
            }
            else
            {
                configuration = new SolutionConfigurationSelector(config);
            }

            monitor = new ConsoleProgressMonitor();
            BuildResult res = item.RunTarget(monitor, command, configuration);

            return((res == null || res.ErrorCount == 0) ? 0 : 1);
        }
        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);
            }
        }
Exemple #12
0
        public void ModelQueries()
        {
            DotNetProject     it2, it3, it4;
            DummySolutionItem it1;
            string            someFile, someId;

            Workspace ws  = new Workspace();
            Workspace cws = new Workspace();

            ws.Items.Add(cws);

            Solution sol1 = new Solution();

            cws.Items.Add(sol1);
            sol1.RootFolder.Items.Add(it1 = new DummySolutionItem());
            sol1.RootFolder.Items.Add(it2 = Services.ProjectService.CreateDotNetProject("C#"));

            Solution sol2 = new Solution();

            cws.Items.Add(sol2);
            SolutionFolder f = new SolutionFolder();

            sol2.RootFolder.Items.Add(f);
            f.Items.Add(it3 = Services.ProjectService.CreateDotNetProject("C#"));
            f.Items.Add(it4 = Services.ProjectService.CreateDotNetProject("C#"));

            it3.Name     = "it3";
            it4.FileName = "/test/it4";
            someFile     = it4.FileName;
            someId       = it3.ItemId;
            Assert.IsFalse(string.IsNullOrEmpty(someId));

            Assert.AreEqual(2, sol1.Items.Count);
            Assert.IsTrue(sol1.Items.Contains(it1));
            Assert.IsTrue(sol1.Items.Contains(it2));

            Assert.AreEqual(2, sol2.Items.Count);
            Assert.IsTrue(sol2.Items.Contains(it3));
            Assert.IsTrue(sol2.Items.Contains(it4));

            var its = ws.GetAllItems <SolutionFolderItem> ().ToList();

            Assert.AreEqual(7, its.Count);
            Assert.IsTrue(its.Contains(it1));
            Assert.IsTrue(its.Contains(it2));
            Assert.IsTrue(its.Contains(it3));
            Assert.IsTrue(its.Contains(it4));
            Assert.IsTrue(its.Contains(sol1.RootFolder));
            Assert.IsTrue(its.Contains(sol2.RootFolder));
            Assert.IsTrue(its.Contains(f));

            var its2 = ws.GetAllItems <DotNetProject> ().ToList();

            Assert.AreEqual(3, its2.Count);
            Assert.IsTrue(its2.Contains(it2));
            Assert.IsTrue(its2.Contains(it3));
            Assert.IsTrue(its2.Contains(it4));

            var its3 = ws.GetAllItems <Project> ().ToList();

            Assert.AreEqual(3, its3.Count);
            Assert.IsTrue(its3.Contains(it2));
            Assert.IsTrue(its3.Contains(it3));
            Assert.IsTrue(its3.Contains(it4));

            var its4 = ws.GetAllItems <Solution> ().ToList();

            Assert.AreEqual(2, its4.Count);
            Assert.IsTrue(its4.Contains(sol1));
            Assert.IsTrue(its4.Contains(sol2));

            var its5 = ws.GetAllItems <WorkspaceItem> ().ToList();

            Assert.AreEqual(4, its5.Count);
            Assert.IsTrue(its5.Contains(ws));
            Assert.IsTrue(its5.Contains(cws));
            Assert.IsTrue(its5.Contains(sol2));
            Assert.IsTrue(its5.Contains(sol2));

            var its6 = ws.GetAllItems <Workspace> ().ToList();

            Assert.AreEqual(2, its6.Count);
            Assert.IsTrue(its6.Contains(ws));
            Assert.IsTrue(its6.Contains(cws));

            SolutionFolderItem si = sol2.GetSolutionItem(someId);

            Assert.AreEqual(it3, si);

            SolutionItem fi = sol2.FindSolutionItem(someFile);

            Assert.AreEqual(it4, fi);

            fi = sol2.FindProjectByName("it3");
            Assert.AreEqual(it3, fi);

            fi = sol2.FindProjectByName("it4");
            Assert.AreEqual(it4, fi);

            fi = sol2.FindProjectByName("it2");
            Assert.IsNull(fi);

            ws.Dispose();
            cws.Dispose();
        }
Exemple #13
0
        public int Run(string[] arguments)
        {
            Console.WriteLine(BrandingService.BrandApplicationName("MonoDevelop Build Tool"));
            foreach (string s in arguments)
            {
                ReadArgument(s);
            }

            if (help)
            {
                Console.WriteLine("build [options] [build-file]");
                Console.WriteLine("-p --project:PROJECT  Name of the project to build.");
                Console.WriteLine("-t --target:TARGET    Name of the target: Build or Clean.");
                Console.WriteLine("-c --configuration:CONFIGURATION  Name of the solution configuration to build.");
                Console.WriteLine("-r --runtime:PREFIX   Prefix of the Mono runtime to build against.");
                Console.WriteLine();
                Console.WriteLine("Supported targets:");
                Console.WriteLine("  {0}: build the project (the default target).", ProjectService.BuildTarget);
                Console.WriteLine("  {0}: clean the project.", ProjectService.CleanTarget);
                Console.WriteLine();
                return(0);
            }

            string solFile  = null;
            string itemFile = null;

            if (file == null)
            {
                string[] files = Directory.GetFiles(".");
                foreach (string f in files)
                {
                    if (Services.ProjectService.IsWorkspaceItemFile(f))
                    {
                        solFile = f;
                        break;
                    }
                    else if (itemFile == null && Services.ProjectService.IsSolutionItemFile(f))
                    {
                        itemFile = f;
                    }
                }
                if (solFile == null && itemFile == null)
                {
                    Console.WriteLine("Project file not found.");
                    return(1);
                }
            }
            else
            {
                if (Services.ProjectService.IsWorkspaceItemFile(file))
                {
                    solFile = file;
                }
                else if (Services.ProjectService.IsSolutionItemFile(file))
                {
                    itemFile = file;
                }
                else
                {
                    Console.WriteLine("File '{0}' is not a project or solution.", file);
                    return(1);
                }
            }

            IProgressMonitor monitor = new ConsoleProjectLoadProgressMonitor(new ConsoleProgressMonitor());

            TargetRuntime targetRuntime  = null;
            TargetRuntime defaultRuntime = Runtime.SystemAssemblyService.DefaultRuntime;

            if (runtime != null)
            {
                targetRuntime = MonoTargetRuntimeFactory.RegisterRuntime(new MonoRuntimeInfo(runtime));
                if (targetRuntime != null)
                {
                    Runtime.SystemAssemblyService.DefaultRuntime = targetRuntime;
                }
            }

            IBuildTarget item;

            if (solFile != null)
            {
                item = Services.ProjectService.ReadWorkspaceItem(monitor, solFile);
            }
            else
            {
                item = Services.ProjectService.ReadSolutionItem(monitor, itemFile);
            }

            using (var readItem = item) {
                if (project != null)
                {
                    Solution solution = item as Solution;
                    item = null;

                    if (solution != null)
                    {
                        item = solution.FindProjectByName(project);
                    }
                    if (item == null)
                    {
                        Console.WriteLine("The project '" + project + "' could not be found in " + file);
                        return(1);
                    }
                }

                IConfigurationTarget configTarget = item as IConfigurationTarget;
                if (config == null && configTarget != null)
                {
                    config = configTarget.DefaultConfigurationId;
                }

                monitor = new ConsoleProgressMonitor();
                BuildResult res = null;
                if (item is SolutionEntityItem && ((SolutionEntityItem)item).ParentSolution == null)
                {
                    ConfigurationSelector configuration = new ItemConfigurationSelector(config);
                    res = item.RunTarget(monitor, command, configuration);
                }
                else
                {
                    ConfigurationSelector configuration      = new SolutionConfigurationSelector(config);
                    SolutionEntityItem    solutionEntityItem = item as SolutionEntityItem;
                    if (solutionEntityItem != null)
                    {
                        if (command == ProjectService.BuildTarget)
                        {
                            res = solutionEntityItem.Build(monitor, configuration, true);
                        }
                        else if (command == ProjectService.CleanTarget)
                        {
                            solutionEntityItem.Clean(monitor, configuration);
                        }
                        else
                        {
                            res = item.RunTarget(monitor, command, configuration);
                        }
                    }
                    else
                    {
                        res = item.RunTarget(monitor, command, configuration);
                    }
                }


                if (targetRuntime != null)
                {
                    Runtime.SystemAssemblyService.DefaultRuntime = defaultRuntime;
                    MonoTargetRuntimeFactory.UnregisterRuntime((MonoTargetRuntime)targetRuntime);
                }

                if (res != null)
                {
                    foreach (var err in res.Errors)
                    {
                        Console.Error.WriteLine(err);
                    }
                }

                return((res == null || res.ErrorCount == 0) ? 0 : 1);
            }
        }