예제 #1
0
            public async Task <(ImmutableArray <MonoDevelopMetadataReference>, ImmutableArray <ProjectReference>)> CreateReferences(
                MonoDevelop.Projects.Project proj,
                string framework,
                CancellationToken token)
            {
                if (!(proj is MonoDevelop.Projects.DotNetProject netProject))
                {
                    return(CreateDefaultMetadataReferences(), ImmutableArray <ProjectReference> .Empty);
                }

                var config = IdeApp.IsInitialized ? IdeApp.Workspace.ActiveConfiguration : MonoDevelop.Projects.ConfigurationSelector.Default;

                if (!string.IsNullOrEmpty(framework))
                {
                    config = new MonoDevelop.Projects.DotNetProjectFrameworkConfigurationSelector(config, framework);
                }

                var data = new AddReferencesData {
                    References            = new List <MonoDevelopMetadataReference> (),
                    ProjectReferences     = new List <ProjectReference> (),
                    Project               = netProject,
                    Visited               = new HashSet <string> (FilePath.PathComparer),
                    AddedProjects         = new HashSet <MonoDevelop.Projects.DotNetProject> (),
                    ConfigurationSelector = config,
                    Token = token
                };

                if (!await AddReferences(data))
                {
                    return(ImmutableArray <MonoDevelopMetadataReference> .Empty, ImmutableArray <ProjectReference> .Empty);
                }
                return(data.References.ToImmutableArray(), data.ProjectReferences.ToImmutableArray());
            }
예제 #2
0
            async Task <bool> AddReferences(AddReferencesData data)
            {
                try {
                    var referencedAssemblies = await data.Project.GetReferencedAssemblies(data.ConfigurationSelector, true).ConfigureAwait(false);

                    foreach (var file in referencedAssemblies)
                    {
                        if (file.IsProjectReference)
                        {
                            var referencedItem = file.GetReferencedItem(data.Project.ParentSolution);
                            if (!(referencedItem is MonoDevelop.Projects.DotNetProject referencedProject))
                            {
                                continue;
                            }

                            if (!IdeApp.TypeSystemService.IsOutputTrackedProject(referencedProject))
                            {
                                if (!file.ReferenceOutputAssembly)
                                {
                                    continue;
                                }

                                if (!data.AddedProjects.Add(referencedProject))
                                {
                                    continue;
                                }

                                string framework = file.HasSingleTargetFramework ? null : file.NearestTargetFramework;
                                var    projectReferenceAliases = file.EnumerateAliases();
                                var    projectId        = projectMap.GetOrCreateId(referencedProject, null, framework);
                                var    projectReference = new ProjectReference(projectId, projectReferenceAliases.ToImmutableArray());
                                data.ProjectReferences.Add(projectReference);

                                continue;
                            }
                        }

                        if (data.Token.IsCancellationRequested)
                        {
                            return(false);
                        }

                        if (!data.Visited.Add(file.FilePath))
                        {
                            continue;
                        }

                        var aliases           = file.EnumerateAliases().ToImmutableArray();
                        var metadataReference = manager.GetOrCreateMetadataReference(file.FilePath, new MetadataReferenceProperties(aliases: aliases));
                        if (metadataReference != null)
                        {
                            data.References.Add(metadataReference);
                        }
                    }

                    return(true);
                } catch (Exception e) {
                    LoggingService.LogError("Error while getting referenced assemblies", e);
                    // TODO: Check whether this should return false, I retained compat for now.
                    return(true);
                }
            }