コード例 #1
0
        public ProjectMetadata(Project project, ILibraryExport projectExport)
        {
            // Get the metadata reference for this project
            var projectReference = projectExport.MetadataReferences.OfType <IMetadataProjectReference>().First(r => string.Equals(r.Name, project.Name, StringComparison.OrdinalIgnoreCase));

            // Get all other metadata references
            var otherReferences = projectExport.MetadataReferences.Where(r => r != projectReference);

            SourceFiles = projectReference.GetSources()
                          .OfType <ISourceFileReference>()
                          .Select(s => s.Path)
                          .ToList();

            RawReferences = otherReferences.OfType <IMetadataEmbeddedReference>().Select(r =>
            {
                return(new
                {
                    Name = r.Name,
                    Bytes = r.Contents
                });
            })
                            .ToDictionary(a => a.Name, a => a.Bytes);

            References = otherReferences.OfType <IMetadataFileReference>()
                         .Select(r => r.Path)
                         .ToList();

            var result = projectReference.GetDiagnostics();

            Errors = result.Errors.ToList();

            Warnings = result.Warnings.ToList();
        }
コード例 #2
0
ファイル: LibraryExporter.cs プロジェクト: voloda/dnx
 private void LogExport(Library library, ILibraryExport export)
 {
     if (Log.IsEnabled(LogLevel.Debug))
     {
         Log.LogDebug($"    Exporting {library.Identity}");
         foreach (var reference in Enumerable.Concat <object>(export.MetadataReferences, export.SourceReferences).Where(o => o != null))
         {
             Log.LogDebug($"      {reference}");
         }
     }
 }
コード例 #3
0
        public Assembly Load(Project project)
        {
            var target = new LibraryKey {
                Name            = project.Name,
                Configuration   = _applicationEnvironment.Configuration,
                TargetFramework = project.GetTargetFramework(_applicationEnvironment.RuntimeFramework).FrameworkName
            };

            var accessor = (ICacheContextAccessor)_serviceProvider.GetService(typeof(ICacheContextAccessor));

            ProjectHostContext hostContext = new ProjectHostContext(
                _serviceProvider,
                project.ProjectDirectory,
                null,
                _extensionFolders.SelectMany(ef => ef.SearchPaths).ToArray(),
                target.Configuration,
                target.TargetFramework,
                new Cache(accessor),
                accessor,
                new NamedCacheDependencyProvider()
                );

            hostContext.DependencyWalker.Walk(project.Name, project.Version, target.TargetFramework);

            var provider = (ILibraryExportProvider)hostContext.ServiceProvider.GetService(typeof(ILibraryExportProvider));

            ILibraryExport export = provider.GetLibraryExport(target);

            if (export == null)
            {
                return(null);
            }

            foreach (var projectReference in export.MetadataReferences.OfType <IMetadataProjectReference>())
            {
                if (string.Equals(projectReference.Name, project.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return(projectReference.Load(_assemblyLoadContextFactory.Create()));
                }
            }

            return(null);
        }
コード例 #4
0
        private static void ProcessExport(ICache cache,
                                          ILibraryExport export,
                                          IDictionary <string, IMetadataReference> metadataReferences,
                                          IDictionary <string, ISourceReference> sourceReferences)
        {
            var references = new List <IMetadataReference>(export.MetadataReferences);

            foreach (var reference in references)
            {
                metadataReferences[reference.Name] = reference;
            }

            if (sourceReferences != null)
            {
                foreach (var sourceReference in export.SourceReferences)
                {
                    sourceReferences[sourceReference.Name] = sourceReference;
                }
            }
        }
コード例 #5
0
 public void AddAdditionalLibraryExportRegistrations(string name, ILibraryExport additionalRegistration)
 {
     AdditionalLibraryExportRegistrations[name] = additionalRegistration;
 }
コード例 #6
0
 public void AddAdditionalLibraryExportRegistrations(string name, ILibraryExport additionalRegistration) {
     AdditionalLibraryExportRegistrations[name] = additionalRegistration;
 }
コード例 #7
0
ファイル: LibraryExporter.cs プロジェクト: elanwu123/dnx
 private void LogExport(Library library, ILibraryExport export)
 {
     if (Log.IsEnabled(LogLevel.Debug))
     {
         Log.LogDebug($"    Exporting {library.Identity}");
         foreach (var reference in Enumerable.Concat<object>(export.MetadataReferences, export.SourceReferences).Where(o => o != null))
         {
             Log.LogDebug($"      {reference}");
         }
     }
 }
コード例 #8
0
        private static void ProcessExport(ICache cache,
                                          ILibraryExport export,
                                          IDictionary<string, IMetadataReference> metadataReferences,
                                          IDictionary<string, ISourceReference> sourceReferences)
        {
            var references = new List<IMetadataReference>(export.MetadataReferences);

            foreach (var reference in references)
            {
                metadataReferences[reference.Name] = reference;
            }

            if (sourceReferences != null)
            {
                foreach (var sourceReference in export.SourceReferences)
                {
                    sourceReferences[sourceReference.Name] = sourceReference;
                }
            }
        }
コード例 #9
0
        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);
            }));
        }