Beispiel #1
0
        public virtual IEnumerable <AbstractDProject> GetReferencedDProjects(ConfigurationSelector configuration)
        {
            AbstractDProject p;

            foreach (var dep in References.ReferencedProjectIds)
            {
                if ((p = ParentSolution.GetSolutionItem(dep) as AbstractDProject) != null)
                {
                    yield return(p);
                }
            }
        }
Beispiel #2
0
 public IList <string> GetUserAssemblyPaths(ConfigurationSelector configuration)
 {
     if (ParentSolution == null)
     {
         return(null);
     }
     //return all projects in the sln in case some are loaded dynamically
     //FIXME: should we do this for the whole workspace?
     return(ParentSolution.GetAllProjects().OfType <DotNetProject> ()
            .Select(d => (string)d.GetOutputFileName(configuration))
            .Where(d => !string.IsNullOrEmpty(d)).ToList());
 }
Beispiel #3
0
        public override IEnumerable <SolutionItem> GetReferencedItems(ConfigurationSelector configuration)
        {
            SolutionItem p;

            foreach (var dep in References.ReferencedProjectIds)
            {
                if ((p = ParentSolution.GetSolutionItem(dep)) != null)
                {
                    yield return(p);
                }
            }
        }
Beispiel #4
0
 internal void NotifyItemRemovedFromFolder(object sender, SolutionItemChangeEventArgs e, bool removedFromSolution)
 {
     DescendantItemRemoved?.Invoke(sender, e);
     if (ParentFolder != null)
     {
         ParentFolder.NotifyItemRemovedFromFolder(sender, e, removedFromSolution);
     }
     else if (ParentSolution != null && removedFromSolution)
     {
         ParentSolution.OnSolutionItemRemoved(e);
     }
 }
Beispiel #5
0
 internal void NotifyItemAddedToFolder(object sender, SolutionItemChangeEventArgs e, bool newToSolution)
 {
     if (ParentFolder != null)
     {
         ParentFolder.NotifyItemAddedToFolder(sender, e, newToSolution);
     }
     else if (ParentSolution != null && newToSolution)
     {
         ParentSolution.OnSolutionItemAdded(e);
     }
     DescendantItemAdded?.Invoke(sender, e);
 }
Beispiel #6
0
 /// <summary>
 /// Checks if this solution item has modified files and has to be built
 /// </summary>
 /// <returns>
 /// <c>true</c> if the solution item has to be built
 /// </returns>
 /// <param name='configuration'>
 /// Configuration for which to do the check
 /// </param>
 public bool NeedsBuilding(ConfigurationSelector configuration)
 {
     using (Counters.NeedsBuildingTimer.BeginTiming("NeedsBuilding check for " + Name)) {
         if (ParentSolution != null && this is SolutionEntityItem)
         {
             SolutionConfiguration sconf = ParentSolution.GetConfiguration(configuration);
             if (sconf != null && !sconf.BuildEnabledForItem((SolutionEntityItem)this))
             {
                 return(false);
             }
         }
         return(Services.ProjectService.GetExtensionChain(this).GetNeedsBuilding(this, configuration));
     }
 }
Beispiel #7
0
        /// <summary>
        /// Gets the projects referenced by the current project
        /// </summary>
        /// <returns>The projects referenced by the current project</returns>
        public IEnumerable <Project> GetReferences()
        {
            List <Project> output = new List <Project>();

            foreach (var item in ProjectReferenceNames)
            {
                var p = ParentSolution.GetProjectsByName(item).FirstOrDefault();
                if (p != null)
                {
                    output.Add(p);
                }
            }
            return(output);
        }
Beispiel #8
0
        void AddProjectReference(string fileName)
        {
            DnxProject project = ParentSolution.FindProjectByProjectJsonFileName(fileName);

            if (project != null)
            {
                var projectItem = new ProjectReference(ReferenceType.Project, project.Name);
                References.Add(projectItem);
            }
            else
            {
                LoggingService.LogDebug("Unable to find project by json filename '{0}'.", fileName);
            }
        }
Beispiel #9
0
        public async Task <BuildResult> Clean(ProgressMonitor monitor, ConfigurationSelector configuration, OperationContext operationContext = null)
        {
            if (ParentSolution == null)
            {
                return(new BuildResult());
            }
            SolutionConfiguration conf = ParentSolution.GetConfiguration(configuration);

            if (conf == null)
            {
                return(new BuildResult());
            }

            if (operationContext == null)
            {
                operationContext = new OperationContext();
            }

            ReadOnlyCollection <SolutionItem> allProjects;

            try {
                allProjects = GetAllBuildableEntries(configuration, true, true);
            } catch (CyclicDependencyException) {
                monitor.ReportError(GettextCatalog.GetString("Cyclic dependencies are not supported."), null);
                return(new BuildResult("", 1, 1));
            }

            monitor.BeginTask(GettextCatalog.GetString("Cleaning Solution: {0} ({1})", Name, configuration.ToString()), allProjects.Count);

            bool        operationStarted = false;
            BuildResult result           = null;

            try {
                operationStarted = ParentSolution != null && await ParentSolution.BeginBuildOperation(monitor, configuration, operationContext);

                return(result = await RunParallelBuildOperation(monitor, configuration, allProjects, (ProgressMonitor m, SolutionItem item) => {
                    return item.Clean(m, configuration, operationContext);
                }, false));
            }
            finally {
                if (operationStarted)
                {
                    await ParentSolution.EndBuildOperation(monitor, configuration, operationContext, result);
                }
                monitor.EndTask();
            }
        }
        protected override void OnClean(IProgressMonitor monitor, ConfigurationSelector configuration)
        {
            if (ParentSolution == null)
            {
                return;
            }
            SolutionConfiguration conf = ParentSolution.GetConfiguration(configuration);

            if (conf == null)
            {
                return;
            }

            try
            {
                monitor.BeginTask(GettextCatalog.GetString("Cleaning Solution: {0} ({1})", Name, configuration.ToString()), Items.Count);

                foreach (SolutionItem item in Items)
                {
                    if (item is SolutionFolder)
                    {
                        item.Clean(monitor, configuration);
                    }
                    else if (item is SolutionEntityItem)
                    {
                        SolutionEntityItem si = (SolutionEntityItem)item;
                        // ce can be null if you add items to the root solution folder which
                        // causes them to be placed in an autogenerated 'Project Items' folder
                        SolutionConfigurationEntry ce = conf.GetEntryForItem(si);
                        if (ce != null && ce.Build)
                        {
                            si.Clean(monitor, ce.ItemConfigurationSelector);
                        }
                    }
                    else
                    {
                        item.Clean(monitor, configuration);
                    }
                    monitor.Step(1);
                }
            }
            finally
            {
                monitor.EndTask();
            }
        }
Beispiel #11
0
        public async Task <BuildResult> Build(ProgressMonitor monitor, ConfigurationSelector configuration, bool buildReferencedTargets = false, OperationContext operationContext = null)
        {
            ReadOnlyCollection <SolutionItem> allProjects;

            try {
                allProjects = GetAllBuildableEntries(configuration, true, true);
            } catch (CyclicDependencyException) {
                monitor.ReportError(GettextCatalog.GetString("Cyclic dependencies are not supported."), null);
                return(new BuildResult("", 1, 1));
            }

            if (operationContext == null)
            {
                operationContext = new OperationContext();
            }

            bool        operationStarted = false;
            BuildResult result           = null;

            try {
                if (Runtime.Preferences.SkipBuildingUnmodifiedProjects)
                {
                    allProjects = allProjects.Where(si => {
                        if (si is Project p)
                        {
                            return(p.FastCheckNeedsBuild(configuration));
                        }
                        return(true);                       //Don't filter things that don't have FastCheckNeedsBuild
                    }).ToList().AsReadOnly();
                }
                monitor.BeginTask(GettextCatalog.GetString("Building Solution: {0} ({1})", Name, configuration.ToString()), allProjects.Count);

                operationStarted = ParentSolution != null && await ParentSolution.BeginBuildOperation(monitor, configuration, operationContext);

                return(result = await RunParallelBuildOperation(monitor, configuration, allProjects, (ProgressMonitor m, SolutionItem item) => {
                    return item.Build(m, configuration, false, operationContext);
                }, false));
            } finally {
                if (operationStarted)
                {
                    await ParentSolution.EndBuildOperation(monitor, configuration, operationContext, result);
                }
                monitor.EndTask();
            }
        }
        public ICompilation ResolveAssemblyDom(string assemblyName)
        {
            var parsed = SystemAssemblyService.ParseAssemblyName(assemblyName);

            if (string.IsNullOrEmpty(parsed.Name))
            {
                return(null);
            }

            var dllName = parsed.Name + ".dll";

            foreach (var reference in References)
            {
                if (reference.ReferenceType == ReferenceType.Package || reference.ReferenceType == ReferenceType.Assembly)
                {
                    foreach (string refPath in reference.GetReferencedFileNames(null))
                    {
                        if (Path.GetFileName(refPath) == dllName)
                        {
                            return(new ICSharpCode.NRefactory.TypeSystem.Implementation.SimpleCompilation(TypeSystemService.LoadAssemblyContext(TargetRuntime, TargetFramework, refPath)));
                        }
                    }
                }
                else if (reference.ReferenceType == ReferenceType.Project && parsed.Name == reference.Reference)
                {
                    var p = ParentSolution.FindProjectByName(reference.Reference) as DotNetProject;
                    if (p == null)
                    {
                        LoggingService.LogWarning("Project '{0}' referenced from '{1}' could not be found", reference.Reference, this.Name);
                        continue;
                    }
                    return(TypeSystemService.GetCompilation(p));
                }
            }

            string path = GetAssemblyPath(assemblyName);

            if (path != null)
            {
                return(new ICSharpCode.NRefactory.TypeSystem.Implementation.SimpleCompilation(TypeSystemService.LoadAssemblyContext(TargetRuntime, TargetFramework, path)));
            }
            return(null);
        }
        public Task <BuildResult> Clean(ProgressMonitor monitor, ConfigurationSelector configuration, OperationContext operationContext = null)
        {
            var slnConf = ParentSolution?.GetConfiguration(configuration);

            if (slnConf == null)
            {
                return(Task.FromResult(new BuildResult()));
            }

            //don't collect dependencies, CleanItems will do it
            var collected = new HashSet <SolutionItem> ();

            CollectBuildableEntries(collected, configuration, slnConf, false);

            return(ParentSolution.CleanItems(
                       monitor, configuration, collected, operationContext,
                       IsRoot ? GettextCatalog.GetString("Cleaning solution {0} ({1})", Name, configuration.ToString()) : null
                       ));
        }
Beispiel #14
0
        void CreateDefaultCatalog(ProgressMonitor monitor)
        {
            IFileScanner[] scanners = TranslationService.GetFileScanners();

            Catalog        catalog  = new Catalog(this);
            List <Project> projects = new List <Project> ();

            foreach (Project p in ParentSolution.GetAllProjects())
            {
                if (IsIncluded(p))
                {
                    projects.Add(p);
                }
            }
            foreach (Project p in projects)
            {
                monitor.Log.WriteLine(GettextCatalog.GetString("Scanning project {0}...", p.Name));
                foreach (ProjectFile file in p.Files)
                {
                    if (!File.Exists(file.FilePath))
                    {
                        continue;
                    }
                    if (file.Subtype == Subtype.Code)
                    {
                        string mimeType = DesktopService.GetMimeTypeForUri(file.FilePath);
                        foreach (IFileScanner fs in scanners)
                        {
                            if (fs.CanScan(this, catalog, file.FilePath, mimeType))
                            {
                                fs.UpdateCatalog(this, catalog, monitor, file.FilePath);
                            }
                        }
                    }
                }
                if (monitor.CancellationToken.IsCancellationRequested)
                {
                    return;
                }
                monitor.Step(1);
            }
            catalog.Save(Path.Combine(this.BaseDirectory, "messages.po"));
        }
Beispiel #15
0
        public ProjectDom ResolveAssemblyDom(string assemblyName)
        {
            var parsed = SystemAssemblyService.ParseAssemblyName(assemblyName);

            if (string.IsNullOrEmpty(parsed.Name))
            {
                return(null);
            }

            var dllName = parsed.Name + ".dll";

            foreach (var reference in References)
            {
                if (reference.ReferenceType == ReferenceType.Package || reference.ReferenceType == ReferenceType.Assembly)
                {
                    foreach (string refPath in reference.GetReferencedFileNames(null))
                    {
                        if (Path.GetFileName(refPath) == dllName)
                        {
                            return(ProjectDomService.GetAssemblyDom(TargetRuntime, refPath));
                        }
                    }
                }
                else if (reference.ReferenceType == ReferenceType.Project && parsed.Name == reference.Reference)
                {
                    var p = ParentSolution.FindProjectByName(reference.Reference) as DotNetProject;
                    if (p == null)
                    {
                        LoggingService.LogWarning("Project '{0}' referenced from '{1}' could not be found", reference.Reference, this.Name);
                        continue;
                    }
                    return(ProjectDomService.GetProjectDom(p));
                }
            }

            string path = GetAssemblyPath(assemblyName);

            if (path != null)
            {
                return(ProjectDomService.GetAssemblyDom(TargetRuntime, path));
            }
            return(null);
        }
Beispiel #16
0
        protected override void OnClean(IProgressMonitor monitor, ConfigurationSelector configuration)
        {
            if (ParentSolution == null)
            {
                return;
            }
            SolutionConfiguration conf = ParentSolution.GetConfiguration(configuration);

            if (conf == null)
            {
                return;
            }

            try {
                monitor.BeginTask(GettextCatalog.GetString("Cleaning Solution {0}", Name), Items.Count);

                foreach (SolutionItem item in Items)
                {
                    if (item is SolutionFolder)
                    {
                        item.Clean(monitor, configuration);
                    }
                    else if (item is SolutionEntityItem)
                    {
                        SolutionEntityItem         si = (SolutionEntityItem)item;
                        SolutionConfigurationEntry ce = conf.GetEntryForItem(si);
                        if (ce.Build)
                        {
                            si.Clean(monitor, ce.ItemConfigurationSelector);
                        }
                    }
                    else
                    {
                        item.Clean(monitor, configuration);
                    }
                    monitor.Step(1);
                }
            }
            finally {
                monitor.EndTask();
            }
        }
Beispiel #17
0
        protected override void OnBoundToSolution()
        {
            if (currentSolution != null)
            {
                DisconnectFromSolution();
            }

            base.OnBoundToSolution();

            ParentSolution.ReferenceAddedToProject     += HandleReferenceAddedToProject;
            ParentSolution.ReferenceRemovedFromProject += HandleReferenceRemovedFromProject;
            ParentSolution.SolutionItemAdded           += HandleSolutionItemAdded;
            currentSolution = ParentSolution;

            // Maybe there is a project that is already referencing this one. It may happen when creating a solution
            // from a template
            foreach (var p in ParentSolution.GetAllItems <DotNetProject> ())
            {
                ProcessProject(p);
            }
        }
Beispiel #18
0
        public override IEnumerable <SolutionItem> GetReferencedItems(ConfigurationSelector configuration)
        {
            List <SolutionItem> items = new List <SolutionItem> ();

            if (ParentSolution == null)
            {
                return(items);
            }

            foreach (ProjectReference pref in References)
            {
                if (pref.ReferenceType == ReferenceType.Project)
                {
                    Project rp = ParentSolution.FindProjectByName(pref.Reference);
                    if (rp != null)
                    {
                        items.Add(rp);
                    }
                }
            }
            return(items);
        }
Beispiel #19
0
        protected override IEnumerable <SolutionItem> OnGetReferencedItems(ConfigurationSelector configuration)
        {
            foreach (var p in base.GetReferencedItems(configuration))
            {
                yield return(p);
            }

            if (ParentSolution == null)
            {
                yield break;
            }

            foreach (Package p in Packages)
            {
                if (p.IsProject && p.Name != Name)
                {
                    var cp = ParentSolution.FindProjectByName(p.Name) as CProject;
                    if (cp != null)
                    {
                        yield return(cp);
                    }
                }
            }
        }
        /// <summary>
        /// Checks if the reference-info passed in comes from another project
        /// in the solution.
        /// Returns the referenced project if there is one, or null if the
        /// reference is not to another project in the solution.
        /// </summary>
        private ProjectInfo_CSharp findProjectReference(ReferenceInfo referenceInfo)
        {
            ProjectInfo_CSharp result = null;

            // We look through each project...
            foreach (ProjectInfo projectInfo in ParentSolution.getProjectInfos())
            {
                // We are only interested in C# projects...
                ProjectInfo_CSharp csProjectInfo = projectInfo as ProjectInfo_CSharp;
                if (csProjectInfo == null)
                {
                    continue;
                }

                // We check each configuration for the project...
                foreach (ProjectConfigurationInfo_CSharp configurationInfo in csProjectInfo.getConfigurationInfos())
                {
                    // We find the absolute path to the output for this configuration...
                    string fullOutputPath       = csProjectInfo.RootFolderAbsolute + "/" + configurationInfo.OutputFolder + "/" + csProjectInfo.OutputFileName;
                    string fullIntermediatePath = csProjectInfo.RootFolderAbsolute + "/" + configurationInfo.IntermediateFolder + "/" + csProjectInfo.OutputFileName;

                    // And we check if the reference passed points to the same assembly...
                    if (Utils.isSamePath(fullOutputPath, referenceInfo.AbsolutePath) == true
                        ||
                        Utils.isSamePath(fullIntermediatePath, referenceInfo.AbsolutePath) == true)
                    {
                        // We've found a match, so we return the project that this
                        // configuration is a part of, as the reference appears to
                        // be a 'project reference' to this project...
                        return(csProjectInfo);
                    }
                }
            }

            return(result);
        }
Beispiel #21
0
        public async Task <SolutionFolderItem> ReloadItem(ProgressMonitor monitor, SolutionFolderItem sitem)
        {
            if (Items.IndexOf(sitem) == -1)
            {
                throw new InvalidOperationException("Solution item '" + sitem.Name + "' does not belong to folder '" + Name + "'");
            }

            if (sitem is SolutionItem item)
            {
                // Load the new item

                SolutionItem newItem;
                try {
                    if (ParentSolution.IsSolutionItemEnabled(item.FileName))
                    {
                        using (var ctx = new SolutionLoadContext(ParentSolution))
                            newItem = await Services.ProjectService.ReadSolutionItem(monitor, item.FileName, null, ctx : ctx, itemGuid : item.ItemId);
                    }
                    else
                    {
                        UnknownSolutionItem e = new UnloadedSolutionItem()
                        {
                            FileName = item.FileName
                        };
                        e.ItemId   = item.ItemId;
                        e.TypeGuid = item.TypeGuid;
                        newItem    = e;
                    }
                } catch (Exception ex) {
                    newItem = new UnknownSolutionItem {
                        LoadError = ex.Message,
                        FileName  = item.FileName
                    };
                }

                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 <SolutionItem> ().FirstOrDefault(it => it.FileName == item.FileName));
                }

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

                item.ParentFolder = null;
                DisconnectChildEntryEvents(item);
                ConnectChildEntryEvents(newItem);

                // Shutdown project builder before the ItemAdded event is fired. This should prevent the old out of
                // date project builder being used by the TypeSystemService when getting reference information. The
                // TypeSystemService loads the project when the ItemAdded event is fired before the item is disposed.
                // Disposing the project will also shutdown the project builder but this happens too late and can
                // result in the old project builder being used which does not have the latest project xml.
                if (item is Project)
                {
                    await RemoteBuildEngineManager.UnloadProject(item.FileName);
                }

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

                item.Dispose();
                return(newItem);
            }

            return(sitem);
        }
Beispiel #22
0
        public async Task <SolutionFolderItem> ReloadItem(ProgressMonitor monitor, SolutionFolderItem sitem)
        {
            if (Items.IndexOf(sitem) == -1)
            {
                throw new InvalidOperationException("Solution item '" + sitem.Name + "' does not belong to folder '" + Name + "'");
            }

            SolutionItem item = sitem as SolutionItem;

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

                SolutionItem newItem;
                try {
                    if (ParentSolution.IsSolutionItemEnabled(item.FileName))
                    {
                        using (var ctx = new SolutionLoadContext(ParentSolution))
                            newItem = await Services.ProjectService.ReadSolutionItem(monitor, item.FileName, null, ctx : ctx, itemGuid : item.ItemId);
                    }
                    else
                    {
                        UnknownSolutionItem e = new UnloadedSolutionItem()
                        {
                            FileName = item.FileName
                        };
                        e.ItemId   = item.ItemId;
                        e.TypeGuid = item.TypeGuid;
                        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 <SolutionItem> ().FirstOrDefault(it => it.FileName == item.FileName));
                }

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

                item.ParentFolder = null;
                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);
            }
        }
Beispiel #23
0
        public void UpdateTranslations(ProgressMonitor monitor, params Translation[] translations)
        {
            monitor.BeginTask(null, Translations.Count + 1);

            try {
                List <Project> projects = new List <Project> ();
                foreach (Project p in ParentSolution.GetAllProjects())
                {
                    if (IsIncluded(p))
                    {
                        projects.Add(p);
                    }
                }
                monitor.BeginTask(GettextCatalog.GetString("Updating message catalog"), projects.Count);
                CreateDefaultCatalog(monitor);
                monitor.Log.WriteLine(GettextCatalog.GetString("Done"));
            } finally {
                monitor.EndTask();
                monitor.Step(1);
            }
            if (monitor.CancellationToken.IsCancellationRequested)
            {
                monitor.Log.WriteLine(GettextCatalog.GetString("Operation cancelled."));
                return;
            }

            Dictionary <string, bool> isIncluded = new Dictionary <string, bool> ();

            foreach (Translation translation in translations)
            {
                isIncluded[translation.IsoCode] = true;
            }
            foreach (Translation translation in this.Translations)
            {
                if (!isIncluded.ContainsKey(translation.IsoCode))
                {
                    continue;
                }
                string poFileName = translation.PoFile;
                monitor.BeginTask(GettextCatalog.GetString("Updating {0}", translation.PoFile), 1);
                try {
                    var pb = new ProcessArgumentBuilder();
                    pb.Add("-U");
                    pb.AddQuoted(poFileName);
                    pb.Add("-v");
                    pb.AddQuoted(this.BaseDirectory.Combine("messages.po"));

                    var process = Runtime.ProcessService.StartProcess(Translation.GetTool("msgmerge"),
                                                                      pb.ToString(), this.BaseDirectory, monitor.Log, monitor.Log, null);
                    process.WaitForOutput();
                }
                catch (System.ComponentModel.Win32Exception) {
                    var msg = GettextCatalog.GetString("Did not find msgmerge. Please ensure that gettext tools are installed.");
                    monitor.ReportError(msg, null);
                }
                catch (Exception ex) {
                    monitor.ReportError(GettextCatalog.GetString("Could not update file {0}", translation.PoFile), ex);
                }
                finally {
                    monitor.EndTask();
                    monitor.Step(1);
                }
                if (monitor.CancellationToken.IsCancellationRequested)
                {
                    monitor.Log.WriteLine(GettextCatalog.GetString("Operation cancelled."));
                    return;
                }
            }
        }
Beispiel #24
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);
            }
        }
Beispiel #25
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 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);
            }
        }
Beispiel #26
0
 internal void OnRunConfigurationsChanged()
 {
     ParentSolution?.NotifyRunConfigurationsChanged();
 }
Beispiel #27
0
        void PopulateSupportFileList(FileCopySet list, ConfigurationSelector configuration, int referenceDistance)
        {
            if (referenceDistance < 2)
            {
                base.PopulateSupportFileList(list, configuration);
            }

            //rename the app.config file
            FileCopySet.Item appConfig = list.Remove("app.config");
            if (appConfig == null)
            {
                appConfig = list.Remove("App.config");
            }
            if (appConfig != null)
            {
                string output = Path.GetFileName(GetOutputFileName(configuration));
                list.Add(appConfig.Src, appConfig.CopyOnlyIfNewer, output + ".config");
            }

            //collect all the "local copy" references and their attendant files
            foreach (ProjectReference projectReference in References)
            {
                if (!projectReference.LocalCopy || ParentSolution == null)
                {
                    continue;
                }

                if (projectReference.ReferenceType == ReferenceType.Project)
                {
                    DotNetProject p = ParentSolution.FindProjectByName(projectReference.Reference) as DotNetProject;

                    if (p == null)
                    {
                        LoggingService.LogWarning("Project '{0}' referenced from '{1}' could not be found", projectReference.Reference, this.Name);
                        continue;
                    }

                    string refOutput = p.GetOutputFileName(configuration);
                    if (string.IsNullOrEmpty(refOutput))
                    {
                        LoggingService.LogWarning("Project '{0}' referenced from '{1}' has an empty output filename", p.Name, this.Name);
                        continue;
                    }

                    list.Add(refOutput);

                    //VS COMPAT: recursively copy references's "local copy" files
                    //but only copy the "copy to output" files from the immediate references
                    p.PopulateSupportFileList(list, configuration, referenceDistance + 1);

                    DotNetProjectConfiguration refConfig = p.GetConfiguration(configuration) as DotNetProjectConfiguration;

                    if (refConfig != null && refConfig.DebugMode)
                    {
                        string mdbFile = TargetRuntime.GetAssemblyDebugInfoFile(refOutput);
                        if (File.Exists(mdbFile))
                        {
                            list.Add(mdbFile);
                        }
                    }
                }
                else if (projectReference.ReferenceType == ReferenceType.Assembly)
                {
                    // VS COMPAT: Copy the assembly, but also all other assemblies referenced by it
                    // that are located in the same folder
                    foreach (string file in GetAssemblyRefsRec(projectReference.Reference, new HashSet <string> ()))
                    {
                        list.Add(file);
                        if (File.Exists(file + ".config"))
                        {
                            list.Add(file + ".config");
                        }
                        string mdbFile = TargetRuntime.GetAssemblyDebugInfoFile(file);
                        if (File.Exists(mdbFile))
                        {
                            list.Add(mdbFile);
                        }
                    }
                }
                else if (projectReference.ReferenceType == ReferenceType.Custom)
                {
                    foreach (string refFile in projectReference.GetReferencedFileNames(configuration))
                    {
                        list.Add(refFile);
                    }
                }
            }
        }