Esempio n. 1
0
        public static ProjectSnapshot Create(string projectDirectory, string configuration, DesignTimeWorkspace workspaceContext, IReadOnlyList <string> projectSearchPaths)
        {
            var projectContextsCollection = workspaceContext.GetProjectContextCollection(projectDirectory);

            if (!projectContextsCollection.ProjectContexts.Any())
            {
                throw new InvalidOperationException($"Unable to find project.json in '{projectDirectory}'");
            }
            GlobalSettings globalSettings;
            var            currentSearchPaths = projectContextsCollection.Project.ResolveSearchPaths(out globalSettings);

            var snapshot = new ProjectSnapshot();

            snapshot.Project            = projectContextsCollection.Project;
            snapshot.ProjectDiagnostics = new List <DiagnosticMessage>(projectContextsCollection.ProjectDiagnostics);
            snapshot.ProjectSearchPaths = currentSearchPaths.ToList();
            snapshot.GlobalJsonPath     = globalSettings?.FilePath;

            foreach (var projectContext in projectContextsCollection.FrameworkOnlyContexts)
            {
                snapshot.ProjectContexts[projectContext.TargetFramework] =
                    ProjectContextSnapshot.Create(projectContext, configuration, currentSearchPaths);
            }

            return(snapshot);
        }
Esempio n. 2
0
        private void SendOutgingMessages()
        {
            _projectInforamtionMessenger.UpdateRemote(_local, _remote);
            _projectDiagnosticsMessenger.UpdateRemote(_local, _remote);

            var unprocessedFrameworks = new HashSet <NuGetFramework>(_remote.ProjectContexts.Keys);

            foreach (var pair in _local.ProjectContexts)
            {
                ProjectContextSnapshot localProjectSnapshot = pair.Value;
                ProjectContextSnapshot remoteProjectSnapshot;

                if (!_remote.ProjectContexts.TryGetValue(pair.Key, out remoteProjectSnapshot))
                {
                    remoteProjectSnapshot             = new ProjectContextSnapshot();
                    _remote.ProjectContexts[pair.Key] = remoteProjectSnapshot;
                }

                unprocessedFrameworks.Remove(pair.Key);

                foreach (var messenger in _messengers)
                {
                    messenger.UpdateRemote(localProjectSnapshot,
                                           remoteProjectSnapshot);
                }
            }

            // Remove all processed frameworks from the remote view
            foreach (var framework in unprocessedFrameworks)
            {
                _remote.ProjectContexts.Remove(framework);
            }

            _globalErrorMessenger.UpdateRemote(_local, _remote);
        }
Esempio 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 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);
        }
Esempio n. 4
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;
        }
Esempio n. 5
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);
        }
Esempio n. 6
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;
        }