Ejemplo n.º 1
0
        public static ProjectContextSnapshot Create(ProjectContext context, string configuration, IEnumerable <string> currentSearchPaths)
        {
            var snapshot = new ProjectContextSnapshot();

            var allDependencyDiagnostics = new List <DiagnosticMessage>();

            allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
            allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(context, currentSearchPaths));

            var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);

            var allExports = context.CreateExporter(configuration)
                             .GetAllExports()
                             .ToDictionary(export => export.Library.Identity.Name);

            var allSourceFiles       = new List <string>(context.ProjectFile.Files.SourceFiles);
            var allFileReferences    = new List <string>();
            var allProjectReferences = new List <ProjectReferenceDescription>();
            var allDependencies      = new Dictionary <string, DependencyDescription>();

            // All exports are returned. When the same library name have a ReferenceAssembly type export and a Package type export
            // both will be listed as dependencies. Prefix "fx/" will be added to ReferenceAssembly type dependency.
            foreach (var export in allExports.Values)
            {
                allSourceFiles.AddRange(export.SourceReferences.Select(f => f.ResolvedPath));
                var diagnostics = diagnosticsLookup[export.Library].ToList();
                var description = DependencyDescription.Create(export.Library, diagnostics, allExports);
                allDependencies[description.Name] = description;

                var projectDescription = export.Library as ProjectDescription;
                if (projectDescription != null)
                {
                    if (projectDescription.Identity.Name != context.ProjectFile.Name)
                    {
                        allProjectReferences.Add(ProjectReferenceDescription.Create(projectDescription));
                    }
                }
                else
                {
                    allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));
                }
            }

            snapshot.RootDependency        = context.ProjectFile.Name;
            snapshot.TargetFramework       = context.TargetFramework;
            snapshot.SourceFiles           = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.CompilerOptions       = context.GetLanguageSpecificCompilerOptions(context.TargetFramework, configuration);
            snapshot.ProjectReferences     = allProjectReferences.OrderBy(reference => reference.Name).ToList();
            snapshot.FileReferences        = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.DependencyDiagnostics = allDependencyDiagnostics;
            snapshot.Dependencies          = allDependencies;

            return(snapshot);
        }
Ejemplo n.º 2
0
        public ProjectInfo(ProjectContext context,
                           string configuration,
                           IEnumerable <string> currentSearchPaths)
        {
            var allExports     = context.CreateExporter(configuration).GetAllExports().ToList();
            var allDiagnostics = context.LibraryManager.GetAllDiagnostics();

            Context       = context;
            Configuration = configuration;

            var allSourceFiles    = new List <string>(context.ProjectFile.Files.SourceFiles);
            var allFileReferences = new List <string>();

            foreach (var export in allExports)
            {
                allSourceFiles.AddRange(export.SourceReferences);
                allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));
            }

            SourceFiles           = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            CompilationAssembiles = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();

            var allProjectReferences = new List <ProjectReferenceDescription>();

            var allDependencyDiagnostics = new List <DiagnosticMessage>();

            allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
            allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(Context, currentSearchPaths));

            var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);

            Dependencies = new Dictionary <string, DependencyDescription>();

            foreach (var library in context.LibraryManager.GetLibraries())
            {
                var diagnostics = diagnosticsLookup[library].ToList();
                var description = DependencyDescription.Create(library, diagnostics);
                Dependencies[description.Name] = description;

                if (library is ProjectDescription && library.Identity.Name != context.ProjectFile.Name)
                {
                    allProjectReferences.Add(ProjectReferenceDescription.Create((ProjectDescription)library));
                }
            }

            DependencyDiagnostics = allDependencyDiagnostics;
            ProjectReferences     = allProjectReferences.OrderBy(reference => reference.Name).ToList();
        }
Ejemplo n.º 3
0
        public static ProjectContextSnapshot Create(ProjectContext context, string configuration, IEnumerable <string> currentSearchPaths)
        {
            var snapshot = new ProjectContextSnapshot();

            var allDependencyDiagnostics = new List <DiagnosticMessage>();

            allDependencyDiagnostics.AddRange(context.LibraryManager.GetAllDiagnostics());
            allDependencyDiagnostics.AddRange(DependencyTypeChangeFinder.Diagnose(context, currentSearchPaths));

            var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);

            var allSourceFiles       = new List <string>(context.ProjectFile.Files.SourceFiles);
            var allFileReferences    = new List <string>();
            var allProjectReferences = new List <ProjectReferenceDescription>();
            var allDependencies      = new Dictionary <string, DependencyDescription>();

            foreach (var export in context.CreateExporter(configuration).GetDependencies())
            {
                allSourceFiles.AddRange(export.SourceReferences);
                allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));

                var library     = export.Library;
                var diagnostics = diagnosticsLookup[library].ToList();
                var description = DependencyDescription.Create(library, diagnostics);
                allDependencies[description.Name] = description;

                var projectDescription = library as ProjectDescription;

                if (projectDescription != null)
                {
                    allProjectReferences.Add(ProjectReferenceDescription.Create(projectDescription));
                }
            }

            snapshot.RootDependency        = context.ProjectFile.Name;
            snapshot.TargetFramework       = context.TargetFramework;
            snapshot.SourceFiles           = allSourceFiles.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.CompilerOptions       = context.ProjectFile.GetCompilerOptions(context.TargetFramework, configuration);
            snapshot.ProjectReferences     = allProjectReferences.OrderBy(reference => reference.Name).ToList();
            snapshot.FileReferences        = allFileReferences.Distinct(StringComparer.OrdinalIgnoreCase).OrderBy(path => path).ToList();
            snapshot.DependencyDiagnostics = allDependencyDiagnostics;
            snapshot.Dependencies          = allDependencies;

            return(snapshot);
        }