public SourceInformationProvider( IMetadataProjectReference project, ILogger logger) { _project = project; _logger = logger; }
private LibraryExport ExportProject(ProjectDescription project, string aspect) { Logger.TraceInformation($"[{nameof(LibraryExporter)}]: {nameof(ExportProject)}({project.Identity.Name}, {aspect}, {project.Framework}, {_configuration})"); var key = Tuple.Create(project.Identity.Name, project.Framework, _configuration, aspect); return(_compilationEngine.CompilationCache.Cache.Get <ProjectExportContext>(key, ctx => { var metadataReferences = new List <IMetadataReference>(); var sourceReferences = new List <ISourceReference>(); var context = new ProjectExportContext(); // Create the compilation context var compilationContext = project.Project.ToCompilationContext(project.Framework, _configuration, aspect); if (!string.IsNullOrEmpty(project.TargetFrameworkInfo?.AssemblyPath)) { // Project specifies a pre-compiled binary. We're done! var assemblyPath = ResolvePath(project.Project, _configuration, project.TargetFrameworkInfo.AssemblyPath); var pdbPath = ResolvePath(project.Project, _configuration, project.TargetFrameworkInfo.PdbPath); metadataReferences.Add(new CompiledProjectMetadataReference(compilationContext, assemblyPath, pdbPath)); } else { // We need to compile the project. var compilerTypeInfo = project.Project.CompilerServices?.ProjectCompiler ?? Project.DefaultCompiler; // Create the project exporter var exporter = _compilationEngine.CreateProjectExporter(project.Project, project.Framework, _configuration); context.LoadContext = _compilationEngine.CreateBuildLoadContext(project.Project, _configuration); // Get the exports for the project dependencies var projectDependenciesExport = new Lazy <LibraryExport>(() => exporter.GetAllDependencies(project.Identity.Name, aspect)); // Find the project compiler var projectCompiler = _compilationEngine.GetCompiler(compilerTypeInfo, context.LoadContext); Logger.TraceInformation($"[{nameof(LibraryExporter)}]: GetProjectReference({compilerTypeInfo.TypeName}, {project.Identity.Name}, {project.Framework}, {aspect})"); // Resolve the project export IMetadataProjectReference projectReference = projectCompiler.CompileProject( compilationContext, () => projectDependenciesExport.Value, () => CompositeResourceProvider.Default.GetResources(project.Project), _configuration); metadataReferences.Add(projectReference); // Shared sources foreach (var sharedFile in project.Project.Files.SharedFiles) { sourceReferences.Add(new SourceFileReference(sharedFile)); } } context.Export = new LibraryExport(metadataReferences, sourceReferences); return context; }).Export); }
public ILibraryExport GetLibraryExport(ILibraryKey target) { Project project; // Can't find a project file with the name so bail if (!_projectResolver.TryResolveProject(target.Name, out project)) { return(null); } Logger.TraceInformation("[{0}]: GetLibraryExport({1}, {2}, {3}, {4})", GetType().Name, target.Name, target.TargetFramework, target.Configuration, target.Aspect); var targetFrameworkInformation = project.GetTargetFramework(target.TargetFramework); // This is the target framework defined in the project. If there were no target frameworks // defined then this is the targetFramework specified if (targetFrameworkInformation.FrameworkName != null) { target = target.ChangeTargetFramework(targetFrameworkInformation.FrameworkName); } var key = Tuple.Create( target.Name, target.TargetFramework, target.Configuration, target.Aspect); var cache = (ICache)_serviceProvider.GetService(typeof(ICache)); return(cache.Get <ILibraryExport>(key, ctx => { // Get the composite library export provider var exportProvider = (ILibraryExportProvider)_serviceProvider.GetService(typeof(ILibraryExportProvider)); var libraryManager = (ILibraryManager)_serviceProvider.GetService(typeof(ILibraryManager)); var metadataReferences = new List <IMetadataReference>(); var sourceReferences = new List <ISourceReference>(); if (!string.IsNullOrEmpty(targetFrameworkInformation.AssemblyPath)) { var assemblyPath = ResolvePath(project, target.Configuration, targetFrameworkInformation.AssemblyPath); var pdbPath = ResolvePath(project, target.Configuration, targetFrameworkInformation.PdbPath); metadataReferences.Add(new CompiledProjectMetadataReference(project, assemblyPath, pdbPath)); } else { var provider = project.LanguageServices?.ProjectReferenceProvider ?? Project.DefaultLanguageService; // Find the default project exporter var projectReferenceProvider = _projectReferenceProviders.GetOrAdd(provider, typeInfo => { return LanguageServices.CreateService <IProjectReferenceProvider>(_serviceProvider, _projectLoadContext.Value, typeInfo); }); Logger.TraceInformation("[{0}]: GetProjectReference({1}, {2}, {3}, {4})", provider.TypeName, target.Name, target.TargetFramework, target.Configuration, target.Aspect); // Get the exports for the project dependencies var projectExport = new Lazy <ILibraryExport>(() => ProjectExportProviderHelper.GetExportsRecursive( cache, libraryManager, exportProvider, target, dependenciesOnly: true)); // Resolve the project export IMetadataProjectReference projectReference = projectReferenceProvider.GetProjectReference( project, target, () => projectExport.Value); metadataReferences.Add(projectReference); // Shared sources foreach (var sharedFile in project.Files.SharedFiles) { sourceReferences.Add(new SourceFileReference(sharedFile)); } } return new LibraryExport(metadataReferences, sourceReferences); })); }
public ILibraryExport GetLibraryExport(string name, FrameworkName targetFramework, string configuration) { Project project; // Can't find a project file with the name so bail if (!_projectResolver.TryResolveProject(name, out project)) { return(null); } Trace.TraceInformation("[{0}]: GetLibraryExport({1}, {2}, {3})", GetType().Name, name, targetFramework, configuration); var targetFrameworkInformation = project.GetTargetFramework(targetFramework); // This is the target framework defined in the project. If there were no target frameworks // defined then this is the targetFramework specified targetFramework = targetFrameworkInformation.FrameworkName ?? targetFramework; var cacheKey = Tuple.Create(name, targetFramework, configuration); return(_exportCache.GetOrAdd(cacheKey, _ => { // Get the composite library export provider var exportProvider = (ILibraryExportProvider)_serviceProvider.GetService(typeof(ILibraryExportProvider)); var libraryManager = (ILibraryManager)_serviceProvider.GetService(typeof(ILibraryManager)); // Get the exports for the project dependencies ILibraryExport projectExport = ProjectExportProviderHelper.GetExportsRecursive( libraryManager, exportProvider, project.Name, targetFramework, configuration, dependenciesOnly: true); var metadataReferences = new List <IMetadataReference>(); var sourceReferences = new List <ISourceReference>(); if (!string.IsNullOrEmpty(targetFrameworkInformation.AssemblyPath)) { var assemblyPath = ResolvePath(project, configuration, targetFrameworkInformation.AssemblyPath); var pdbPath = ResolvePath(project, configuration, targetFrameworkInformation.PdbPath); metadataReferences.Add(new CompiledProjectMetadataReference(project, assemblyPath, pdbPath)); } else { // Find the default project exporter var projectReferenceProvider = _projectReferenceProviders.GetOrAdd(project.LanguageServices.ProjectReferenceProvider, typeInfo => { return LanguageServices.CreateService <IProjectReferenceProvider>(_serviceProvider, typeInfo); }); Trace.TraceInformation("[{0}]: GetProjectReference({1}, {2}, {3})", project.LanguageServices.ProjectReferenceProvider.TypeName, name, targetFramework, configuration); // Resolve the project export IMetadataProjectReference projectReference = projectReferenceProvider.GetProjectReference( project, targetFramework, configuration, projectExport.MetadataReferences, projectExport.SourceReferences, metadataReferences); metadataReferences.Add(projectReference); // Shared sources foreach (var sharedFile in project.SharedFiles) { sourceReferences.Add(new SourceFileReference(sharedFile)); } } return new LibraryExport(metadataReferences, sourceReferences); })); }
public static LibraryExport ExportProject(Project project, CompilationEngine compilationEngine, string aspect, FrameworkName targetFramework, string configuration) { Logger.TraceInformation($"[{nameof(ProjectExporter)}]: {nameof(ExportProject)}({project.Name}, {aspect}, {targetFramework}, {configuration})"); var targetFrameworkInformation = project.GetTargetFramework(targetFramework); // This is the target framework defined in the project. If there were no target frameworks // defined then this is the targetFramework specified if (targetFrameworkInformation.FrameworkName != null) { targetFramework = targetFrameworkInformation.FrameworkName; } var key = Tuple.Create(project.Name, targetFramework, configuration, aspect); return(compilationEngine.CompilationCache.Cache.Get <LibraryExport>(key, ctx => { var metadataReferences = new List <IMetadataReference>(); var sourceReferences = new List <ISourceReference>(); if (!string.IsNullOrEmpty(targetFrameworkInformation.AssemblyPath)) { // Project specifies a pre-compiled binary. We're done! var assemblyPath = ResolvePath(project, configuration, targetFrameworkInformation.AssemblyPath); var pdbPath = ResolvePath(project, configuration, targetFrameworkInformation.PdbPath); metadataReferences.Add(new CompiledProjectMetadataReference(project.ToCompilationContext(targetFramework, configuration, aspect), assemblyPath, pdbPath)); } else { // We need to compile the project. var provider = project.CompilerServices?.ProjectCompiler ?? Project.DefaultCompiler; // Find the project compiler var projectCompiler = compilationEngine.GetCompiler(provider); Logger.TraceInformation("[{0}]: GetProjectReference({1}, {2}, {3}, {4})", provider.TypeName, project.Name, targetFramework, configuration, aspect); // Get the exports for the project dependencies var projectExport = new Lazy <LibraryExport>(() => ExportProjectDependencies(project, targetFramework, configuration, aspect, compilationEngine)); // Resolve the project export IMetadataProjectReference projectReference = projectCompiler.CompileProject( project.ToCompilationContext(targetFramework, configuration, aspect), () => projectExport.Value, () => CompositeResourceProvider.Default.GetResources(project)); metadataReferences.Add(projectReference); // Shared sources foreach (var sharedFile in project.Files.SharedFiles) { sourceReferences.Add(new SourceFileReference(sharedFile)); } } return new LibraryExport(metadataReferences, sourceReferences); })); }