public override void SaveProject(MonoDevelop.Core.IProgressMonitor monitor, MonoDevelop.Projects.SolutionEntityItem item, MSBuildProject project)
        {
            var changed = UpgradeMonoGameProject(monitor, item, project);

            base.SaveProject(monitor, item, project);
            if (changed)
            {
                this.LoadProject(monitor, item, project);
            }
        }
 public void ExecuteCommand(IProgressMonitor monitor, SolutionEntityItem entry, CustomCommandType type, ConfigurationSelector configuration)
 {
     ExecuteCommand(monitor, entry, type, null, configuration);
 }
        static bool UpgradeMonoGameProject(MonoDevelop.Core.IProgressMonitor monitor, MonoDevelop.Projects.SolutionEntityItem item, MSBuildProject project)
        {
            bool needsSave    = false;
            bool containsMGCB = project.ItemGroups.Any(x => x.Items.Any(i => System.IO.Path.GetExtension(i.Include) == ".mgcb"));
            bool isMonoGame   = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "MonoGamePlatform")) ||
                                project.ItemGroups.Any(x => x.Items.Any(i => i.Name == "Reference" && i.Include == "MonoGame.Framework")) ||
                                containsMGCB;
            bool isApplication = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "OutputType" && p.GetValue() == "Exe")) ||
                                 project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "AndroidApplication" && string.Compare(p.GetValue(), bool.TrueString, true) == 0));
            bool isShared = project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "HasSharedItems" && p.GetValue() == "true"));
            var  type     = item.GetType().Name;

            monitor.Log.WriteLine("Found {0}", type);
            var platform = Environment.OSVersion.Platform == PlatformID.Win32NT ? "Windows" : "DesktopGL";
            var path     = MonoGameExtensionsPath;

            switch (type)
            {
            case "XamarinIOSProject":
                platform = "iOS";
                break;

            case "MonoDroidProject":
                platform = "Android";
                break;

            case "XamMac2Project":
            case "MonoGameProject":
                platform = "DesktopGL";
                break;

            case "XamMac":
            case "XamMacProject":
                platform = "DesktopGL";
                // Xamarin.Mac Classic does not use MSBuild so we need to absolute path.
                path = MonoGameExtensionsAbsolutePath;
                break;

            case "MonoMac":
            case "MonoMacProject":
                platform = "MacOSX";
                // Xamarin.Mac Classic does not use MSBuild so we need to absolute path.
                path = MonoGameExtensionsAbsolutePath;
                break;
            }
            monitor.Log.WriteLine("Platform = {0}", platform);
            monitor.Log.WriteLine("Path = {0}", path);
            monitor.Log.WriteLine("isMonoGame {0}", isMonoGame);
            if (isMonoGame)
            {
                var ritems = new List <MSBuildItem> ();
                foreach (var ig in project.ItemGroups)
                {
                    foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "MonoGame.Framework"))
                    {
                        if (!i.HasMetadata("HintPath"))
                        {
                            monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include);
                            var a = ig.AddNewItem("Reference", i.Include);
                            a.SetMetadata("HintPath", string.Format(path, platform, "MonoGame.Framework.dll"));
                            ritems.Add(i);
                            needsSave = true;
                        }
                    }
                    foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "Tao.Sdl"))
                    {
                        if (!i.HasMetadata("HintPath"))
                        {
                            monitor.Log.WriteLine("Fixing {0} to be Tao.Sdl", i.Include);
                            var a = ig.AddNewItem("Reference", i.Include);
                            a.SetMetadata("HintPath", string.Format(path, platform, "Tao.Sdl.dll"));
                            ritems.Add(i);
                            needsSave = true;
                        }
                    }
                    foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include.StartsWith("OpenTK") &&
                                                     (platform != "iOS" && platform != "Android")))
                    {
                        if (!i.HasMetadata("HintPath"))
                        {
                            monitor.Log.WriteLine("Fixing {0} to be OpenTK", i.Include);
                            var a = ig.AddNewItem("Reference", i.Include);
                            a.SetMetadata("HintPath", string.Format(path, platform, "OpenTK.dll"));
                            a.SetMetadata("SpecificVersion", "true");
                            ritems.Add(i);
                            needsSave = true;
                        }
                    }
                    foreach (var i in ig.Items.Where(x => x.Name == "Reference" && x.Include == "NVorbis"))
                    {
                        if (!i.HasMetadata("HintPath"))
                        {
                            monitor.Log.WriteLine("Fixing {0} to be NVorbis", i.Include);
                            var a = ig.AddNewItem("Reference", i.Include);
                            a.SetMetadata("HintPath", string.Format(path, platform, "NVorbis.dll"));
                            ritems.Add(i);
                            needsSave = true;
                        }
                    }
                }
                foreach (var a in ritems)
                {
                    project.RemoveItem(a);
                }
                var dotNetProject = item as DotNetProject;
                if (dotNetProject != null && (type == "MonoMacProject" || type == "XamMacProject"))
                {
                    var items    = new List <ProjectReference> ();
                    var newitems = new List <ProjectReference> ();
                    foreach (var reference in dotNetProject.References)
                    {
                        if (reference.Reference == "MonoGame.Framework" && string.IsNullOrEmpty(reference.HintPath))
                        {
                            items.Add(reference);
                            newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "MonoGame.Framework.dll")));
                        }
                        if (reference.Reference.StartsWith("OpenTK") && string.IsNullOrEmpty(reference.HintPath))
                        {
                            items.Add(reference);
                            newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "OpenTK.dll")));
                        }
                        if (reference.Reference == "NVorbis" && string.IsNullOrEmpty(reference.HintPath))
                        {
                            items.Add(reference);
                            newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "NVorbis.dll")));
                        }
                        if (reference.Reference == "Tao.Sdl" && string.IsNullOrEmpty(reference.HintPath))
                        {
                            items.Add(reference);
                            newitems.Add(new ProjectReference(ReferenceType.Assembly, reference.Reference, string.Format(path, platform, "Tao.Sdl.dll")));
                        }
                    }
                    dotNetProject.References.RemoveRange(items);
                    dotNetProject.References.AddRange(newitems);
                }
            }
            if (isMonoGame && containsMGCB && (isApplication || isShared))
            {
                if (!project.PropertyGroups.Any(x => x.Properties.Any(p => p.Name == "MonoGamePlatform")) && !isShared)
                {
                    monitor.Log.WriteLine("Adding MonoGamePlatform", platform);
                    project.PropertyGroups.First().SetPropertyValue("MonoGamePlatform", platform, true);
                    needsSave = true;
                }
                if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameCommonProps, StringComparison.OrdinalIgnoreCase)) && !isShared)
                {
                    monitor.Log.WriteLine("Adding MonoGame.Common.props Import");
                    var e       = project.Document.DocumentElement;
                    var manager = new XmlNamespaceManager(new NameTable());
                    var schema  = "http://schemas.microsoft.com/developer/msbuild/2003";
                    manager.AddNamespace("tns", schema);
                    var import = project.Document.CreateElement("Import", schema);
                    import.SetAttribute("Project", MonoGameCommonProps);
                    import.SetAttribute("Condition", string.Format("Exists('{0}')", MonoGameCommonProps));
                    project.Document.DocumentElement.InsertBefore(import, project.Document.DocumentElement.FirstChild);
                    needsSave = true;
                }
                if (containsMGCB)
                {
                    var ritems = new List <MSBuildItem> ();
                    foreach (var ig in project.ItemGroups)
                    {
                        foreach (var i in ig.Items.Where(x => System.IO.Path.GetExtension(x.Include) == ".mgcb"))
                        {
                            if (i.Name != "MonoGameContentReference" && i.Name == "None")
                            {
                                monitor.Log.WriteLine("Fixing {0} to be MonoGameContentReference", i.Include);
                                ig.AddNewItem("MonoGameContentReference", i.Include);
                                ritems.Add(i);
                                needsSave = true;
                            }
                        }
                    }
                    foreach (var a in ritems)
                    {
                        project.RemoveItem(a);
                    }
                }
                if (!project.Imports.Any(x => x.Project.StartsWith(MonoGameContentBuildTargets, StringComparison.OrdinalIgnoreCase)) && !isShared)
                {
                    monitor.Log.WriteLine("Adding MonoGame Content Builder .targets");
                    project.AddNewImport(MonoGameContentBuildTargets);
                    needsSave = true;
                }
            }
            return(needsSave);
        }
Example #4
0
        internal void InternalWriteSolutionItem(IProgressMonitor monitor, string file, SolutionEntityItem item)
        {
            string newFile = WriteFile(monitor, file, item, null);

            if (newFile != null)
            {
                item.FileName = newFile;
            }
            else
            {
                throw new InvalidOperationException("FileFormat not provided for solution item '" + item.Name + "'");
            }
        }
Example #5
0
 public override List <FilePath> GetItemFiles(SolutionEntityItem entry, bool includeReferencedFiles)
 {
     return(entry.OnGetItemFiles(includeReferencedFiles));
 }
Example #6
0
 internal override BuildResult Compile(IProgressMonitor monitor, SolutionEntityItem item, BuildData buildData, ItemCompileCallback callback)
 {
     return(callback(monitor, item, buildData));
 }
Example #7
0
        /// <summary>
        /// Builds the solution item
        /// </summary>
        /// <param name='monitor'>
        /// A progress monitor
        /// </param>
        /// <param name='configuration'>
        /// Configuration to use to build the project
        /// </param>
        /// <param name='buildReferences'>
        /// When set to <c>true</c>, the referenced items will be built before building this item
        /// </param>
        public BuildResult Build(IProgressMonitor monitor, ConfigurationSelector solutionConfiguration, bool buildReferences)
        {
            ITimeTracker tt = Counters.BuildProjectTimer.BeginTiming("Building " + Name);

            try {
                if (!buildReferences)
                {
                    if (!NeedsBuilding(solutionConfiguration))
                    {
                        return(new BuildResult(new CompilerResults(null), ""));
                    }

                    try {
                        SolutionEntityItem        it    = this as SolutionEntityItem;
                        SolutionItemConfiguration iconf = it != null?it.GetConfiguration(solutionConfiguration) : null;

                        string confName = iconf != null ? iconf.Id : solutionConfiguration.ToString();
                        monitor.BeginTask(GettextCatalog.GetString("Building: {0} ({1})", Name, confName), 1);

                        // This will end calling OnBuild ()
                        return(RunTarget(monitor, ProjectService.BuildTarget, solutionConfiguration));
                    } finally {
                        monitor.EndTask();
                    }
                }

                // Get a list of all items that need to be built (including this),
                // and build them in the correct order

                List <SolutionItem> referenced = new List <SolutionItem> ();
                Set <SolutionItem>  visited    = new Set <SolutionItem> ();
                GetBuildableReferencedItems(visited, referenced, this, solutionConfiguration);

                ReadOnlyCollection <SolutionItem> sortedReferenced = SolutionFolder.TopologicalSort(referenced, solutionConfiguration);

                BuildResult cres = new BuildResult();
                cres.BuildCount = 0;
                HashSet <SolutionItem> failedItems = new HashSet <SolutionItem> ();

                monitor.BeginTask(null, sortedReferenced.Count);
                foreach (SolutionItem p in sortedReferenced)
                {
                    if (p.NeedsBuilding(solutionConfiguration) && !p.ContainsReferences(failedItems, solutionConfiguration))
                    {
                        BuildResult res = p.Build(monitor, solutionConfiguration, false);
                        cres.Append(res);
                        if (res.ErrorCount > 0)
                        {
                            failedItems.Add(p);
                        }
                    }
                    else
                    {
                        failedItems.Add(p);
                    }
                    monitor.Step(1);
                    if (monitor.IsCancelRequested)
                    {
                        break;
                    }
                }
                monitor.EndTask();
                return(cres);
            } finally {
                tt.End();
            }
        }
        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);
        }
Example #9
0
 protected virtual void Execute(IProgressMonitor monitor, SolutionEntityItem item, ExecutionContext context, ConfigurationSelector configuration)
 {
     GetNext(item).Execute(monitor, (IBuildTarget)item, context, configuration);
 }
Example #10
0
 protected virtual BuildResult Build(IProgressMonitor monitor, SolutionEntityItem item, ConfigurationSelector configuration)
 {
     return(GetNext(item).RunTarget(monitor, item, ProjectService.BuildTarget, configuration));
 }
Example #11
0
 protected virtual void Clean(IProgressMonitor monitor, SolutionEntityItem item, ConfigurationSelector configuration)
 {
     GetNext(item).RunTarget(monitor, item, ProjectService.CleanTarget, configuration);
 }
Example #12
0
 protected virtual bool SupportsExecute(SolutionEntityItem item)
 {
     return(GetNext(item).SupportsExecute((IBuildTarget)item));
 }
Example #13
0
 protected virtual bool SupportsTarget(SolutionEntityItem item, string target)
 {
     return(GetNext(item).SupportsTarget((IBuildTarget)item, target));
 }
Example #14
0
 public ConfigurationEventArgs(SolutionEntityItem entry, ItemConfiguration configuration) : base(entry)
 {
     this.configuration = configuration;
 }
        string FindMatchingConfiguration(SolutionEntityItem item)
        {
            SolutionItemConfiguration startupConfiguration = null;

            // There are no configurations so do nothing
            if (item.Configurations.Count == 0)
            {
                return(null);
            }

            // Direct match if there's the same name and platform
            if (item.Configurations [Id] != null)
            {
                return(Id);
            }

            // This configuration is not present in the project. Try to find the best match.
            // First of all try matching name
            foreach (SolutionItemConfiguration iconf in item.Configurations)
            {
                if (iconf.Name == Name && iconf.Platform == "")
                {
                    return(iconf.Id);
                }
            }

            // Run some heuristics based on the startup project if it exists
            if (ParentSolution != null && ParentSolution.StartupItem != null)
            {
                var startup = ParentSolution.StartupItem;
                startupConfiguration = startup.GetConfiguration(Selector);
                if (startupConfiguration != null)
                {
                    var match = startupConfiguration.FindBestMatch(item.Configurations);
                    if (match != null)
                    {
                        return(match.Id);
                    }
                }
            }
            if (Platform.Length > 0)
            {
                // No name coincidence, now try matching the platform
                foreach (SolutionItemConfiguration iconf in item.Configurations)
                {
                    if (iconf.Platform == Platform)
                    {
                        return(iconf.Id);
                    }
                }
            }

            // Now match name, ignoring platform
            foreach (SolutionItemConfiguration iconf in item.Configurations)
            {
                if (iconf.Name == Name)
                {
                    return(iconf.Id);
                }
            }

            // No luck. Pick whatever.
            return(item.Configurations [0].Id);
        }
        public override void Save(IProgressMonitor monitor, SolutionEntityItem item)
        {
//			if (item is CompiledAssemblyProject)
//				return;
            base.Save(monitor, item);
        }
Example #17
0
        public SolutionItem ReloadItem(IProgressMonitor monitor, SolutionItem sitem)
        {
            if (Items.IndexOf(sitem) == -1)
            {
                throw new InvalidOperationException("Solution item '" + sitem.Name + "' does not belong to folder '" + Name + "'");
            }

            SolutionEntityItem item = sitem as SolutionEntityItem;

            if (item != null)
            {
                // Load the new item

                SolutionEntityItem newItem;
                try {
                    if (ParentSolution.IsSolutionItemEnabled(item.FileName))
                    {
                        newItem = Services.ProjectService.ReadSolutionItem(monitor, item.FileName);
                    }
                    else
                    {
                        UnknownSolutionItem e = new UnloadedSolutionItem()
                        {
                            FileName = item.FileName
                        };
                        var ch = item.GetItemHandler() as MonoDevelop.Projects.Formats.MSBuild.MSBuildHandler;
                        if (ch != null)
                        {
                            var h = new MonoDevelop.Projects.Formats.MSBuild.MSBuildHandler(ch.TypeGuid, ch.ItemId)
                            {
                                Item = e,
                            };
                            e.SetItemHandler(h);
                        }
                        newItem = e;
                    }
                } catch (Exception ex) {
                    UnknownSolutionItem e = new UnknownSolutionItem();
                    e.LoadError = ex.Message;
                    e.FileName  = item.FileName;
                    newItem     = e;
                }

                if (!Items.Contains(item))
                {
                    // The old item is gone, which probably means it has already been reloaded (BXC20615), or maybe removed.
                    // In this case, there isn't anything else we can do
                    newItem.Dispose();

                    // Find the replacement if it exists
                    return(Items.OfType <SolutionEntityItem> ().FirstOrDefault(it => it.FileName == item.FileName));
                }

                // Replace in the file list
                Items.Replace(item, newItem);

                DisconnectChildEntryEvents(item);
                ConnectChildEntryEvents(newItem);

                NotifyModified("Items");
                OnItemRemoved(new SolutionItemChangeEventArgs(item, ParentSolution, true)
                {
                    ReplacedItem = item
                }, true);
                OnItemAdded(new SolutionItemChangeEventArgs(newItem, ParentSolution, true)
                {
                    ReplacedItem = item
                }, true);

                item.Dispose();
                return(newItem);
            }
            else
            {
                return(sitem);
            }
        }
Example #18
0
 protected virtual bool CanExecute(SolutionEntityItem item, ExecutionContext context, ConfigurationSelector configuration)
 {
     return(GetNext(item).CanExecute((IBuildTarget)item, context, configuration));
 }
Example #19
0
        public SolutionConfigurationEntry AddItem(SolutionEntityItem item)
        {
            string conf = FindMatchingConfiguration(item);

            return(AddItem(item, conf != null, conf));
        }
Example #20
0
 protected virtual IEnumerable <ExecutionTarget> GetExecutionTargets(SolutionEntityItem item, ConfigurationSelector configuration)
 {
     return(GetNext(item).GetExecutionTargets((IBuildTarget)item, configuration));
 }
Example #21
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);
            }
        }
Example #22
0
 protected virtual bool GetNeedsBuilding(SolutionEntityItem item, ConfigurationSelector configuration)
 {
     return(GetNext(item).GetNeedsBuilding((IBuildTarget)item, configuration));
 }
Example #23
0
 public override void Save(IProgressMonitor monitor, SolutionEntityItem entry)
 {
     FileService.RequestFileEdit(entry.GetItemFiles(false));
     entry.OnSave(monitor);
 }
Example #24
0
 protected virtual void SetNeedsBuilding(SolutionEntityItem item, bool val, ConfigurationSelector configuration)
 {
     GetNext(item).SetNeedsBuilding((IBuildTarget)item, val, configuration);
 }
Example #25
0
 internal void SetParentItem(SolutionEntityItem item)
 {
     parentItem = item;
 }
Example #26
0
 protected virtual BuildResult Compile(IProgressMonitor monitor, SolutionEntityItem item, BuildData buildData)
 {
     return(GetNext(item).Compile(monitor, item, buildData, compileCallbackStack.Peek()));
 }
Example #27
0
 public override void Save(IProgressMonitor monitor, SolutionEntityItem entry)
 {
     entry.OnSave(monitor);
 }
Example #28
0
 public virtual void Save(IProgressMonitor monitor, SolutionEntityItem item)
 {
     GetNext(item).Save(monitor, item);
 }
Example #29
0
 public virtual List <FilePath> GetItemFiles(SolutionEntityItem item, bool includeReferencedFiles)
 {
     return(GetNext(item).GetItemFiles(item, includeReferencedFiles));
 }
        public SolutionItem ReloadItem(IProgressMonitor monitor, SolutionItem sitem)
        {
            if (Items.IndexOf(sitem) == -1)
            {
                throw new InvalidOperationException("Solution item '" + sitem.Name + "' does not belong to folder '" + Name + "'");
            }

            SolutionEntityItem item = sitem as SolutionEntityItem;

            if (item != null)
            {
                // Load the new item

                SolutionEntityItem newItem;
                try {
                    if (ParentSolution.IsSolutionItemEnabled(item.FileName))
                    {
                        newItem = Services.ProjectService.ReadSolutionItem(monitor, item.FileName);
                    }
                    else
                    {
                        UnknownSolutionItem e = new UnknownSolutionItem()
                        {
                            FileName      = item.FileName,
                            UnloadedEntry = true
                        };
                        var ch = item.GetItemHandler() as MonoDevelop.Projects.Formats.MSBuild.MSBuildHandler;
                        if (ch != null)
                        {
                            var h = new MonoDevelop.Projects.Formats.MSBuild.MSBuildHandler(ch.TypeGuid, ch.ItemId)
                            {
                                Item = e,
                            };
                            e.SetItemHandler(h);
                        }
                        newItem = e;
                    }
                } catch (Exception ex) {
                    UnknownSolutionItem e = new UnknownSolutionItem();
                    e.LoadError = ex.Message;
                    e.FileName  = item.FileName;
                    newItem     = e;
                }

                // Replace in the file list
                Items.Replace(item, newItem);

                DisconnectChildEntryEvents(item);
                ConnectChildEntryEvents(newItem);

                NotifyModified("Items");
                OnItemRemoved(new SolutionItemChangeEventArgs(item, ParentSolution, true)
                {
                    ReplacedItem = item
                }, true);
                OnItemAdded(new SolutionItemChangeEventArgs(newItem, ParentSolution, true)
                {
                    ReplacedItem = item
                }, true);

                item.Dispose();
                return(newItem);
            }
            else
            {
                return(sitem);
            }
        }