コード例 #1
0
        public CompilationEngine(
            CompilationCache compilationCache,
            CompilationEngineContext context)
        {
            _context             = context;
            RootLibraryExporter  = new LibraryExporter(_context.LibraryManager, this, _context.TargetFramework, _context.Configuration);
            _compilerLoadContext = new Lazy <IAssemblyLoadContext>(() =>
            {
                var factory = (IAssemblyLoadContextFactory)_context.Services.GetService(typeof(IAssemblyLoadContextFactory));

                // Ensure this compilation engine is in the service provider
                var services = new ServiceProvider(_context.Services);
                services.Add(typeof(ICompilationEngine), this);
                return(factory.Create(services));
            });

            CompilationCache = compilationCache;

            // Register compiler services
            // TODO(anurse): Switch to project factory model to avoid needing to do this.
            _context.AddService(typeof(ICache), CompilationCache.Cache);
            _context.AddService(typeof(ICacheContextAccessor), CompilationCache.CacheContextAccessor);
            _context.AddService(typeof(INamedCacheDependencyProvider), CompilationCache.NamedCacheDependencyProvider);
            _context.AddService(typeof(IFileWatcher), context.FileWatcher);
        }
コード例 #2
0
ファイル: BuildLoadContext.cs プロジェクト: adwardliu/dnx
 public BuildLoadContext(Project project,
                         CompilationEngine compilationEngine,
                         CompilationEngineContext compilationEngineContext)
 {
     _project = project;
     _compilationEngine = compilationEngine;
     _compilationEngineContext = compilationEngineContext;
 }
コード例 #3
0
ファイル: BuildLoadContext.cs プロジェクト: rajeevkb/dnx
 public BuildLoadContext(Project project,
                         CompilationEngine compilationEngine,
                         CompilationEngineContext compilationEngineContext)
 {
     _project                  = project;
     _compilationEngine        = compilationEngine;
     _compilationEngineContext = compilationEngineContext;
 }
コード例 #4
0
ファイル: BuildLoadContext.cs プロジェクト: leloulight/dnx
 public BuildLoadContext(Project project,
                         CompilationEngine compilationEngine,
                         CompilationEngineContext compilationEngineContext,
                         string configuration)
 {
     _project                  = project;
     _compilationEngine        = compilationEngine;
     _compilationEngineContext = compilationEngineContext;
     _configuration            = configuration;
 }
コード例 #5
0
ファイル: BuildLoadContext.cs プロジェクト: leloulight/dnx
 public BuildLoadContext(Project project,
                         CompilationEngine compilationEngine,
                         CompilationEngineContext compilationEngineContext,
                         string configuration)
 {
     _project = project;
     _compilationEngine = compilationEngine;
     _compilationEngineContext = compilationEngineContext;
     _configuration = configuration;
 }
コード例 #6
0
ファイル: coreclrembedding.cs プロジェクト: Glidias/edge
        public EdgeAssemblyLoadContext(EdgeAssemblyLoadContextAccessor loadContextAccessor)
        {
            DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Starting");
            DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Application root is {0}", RuntimeEnvironment.ApplicationDirectory);

            _loadContextAccessor = loadContextAccessor;

            if (File.Exists(Path.Combine(RuntimeEnvironment.ApplicationDirectory, "project.lock.json")))
            {
                IList<LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(ApplicationHostContext);
                Dictionary<string, ProjectDescription> projects = libraries.Where(p => p.Type == LibraryTypes.Project).ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p);
                Dictionary<AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries);
                
                CompilationEngineContext compilationContext = new CompilationEngineContext(ApplicationEnvironment, RuntimeEnvironment, this, new CompilationCache());
                CompilationEngine compilationEngine = new CompilationEngine(compilationContext);

                AddCompileAssemblies(libraries);

                _loaders.Add(new ProjectAssemblyLoader(_loadContextAccessor, compilationEngine, projects.Values));
                _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries));
            }

            else
            {
                _noProjectJsonFile = true;

                if (File.Exists(Path.Combine(RuntimeEnvironment.EdgeNodePath, "project.lock.json")))
                {
                    ApplicationHostContext stockHostContext = new ApplicationHostContext
                    {
                        ProjectDirectory = RuntimeEnvironment.EdgeNodePath,
                        TargetFramework = TargetFrameworkName
                    };

                    IList<LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(stockHostContext);
                    Dictionary<AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries);

                    AddCompileAssemblies(libraries);

                    _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries));
                }
            }

            DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Created the dependency providers for the application");
        }
コード例 #7
0
ファイル: CompilationEngine.cs プロジェクト: leloulight/dnx
 public CompilationEngine(CompilationEngineContext context)
 {
     _context         = context;
     CompilationCache = _context.CompilationCache;
 }
コード例 #8
0
 private CompilationEngine CreateEngineCore(CompilationEngineContext context)
 {
     return(new CompilationEngine(
                CompilationCache,
                context));
 }
コード例 #9
0
 // Having two versions of this allows consumers of the concrete Factory type to avoid casting the output by calling the
 // above version, while people calling through the interface (i.e. the runtime) can get the interface
 ICompilationEngine ICompilationEngineFactory.CreateEngine(CompilationEngineContext context)
 {
     return(CreateEngineCore(context));
 }
コード例 #10
0
 public CompilationEngine CreateEngine(CompilationEngineContext context)
 {
     return(CreateEngineCore(context));
 }
コード例 #11
0
        public Assembly Load(AssemblyName assemblyName)
        {
            return _cache.Get<Assembly>(assemblyName.Name, cacheContext =>
            {
                var reference = _libraryManager.GetMetadataReference(assemblyName.Name);

                if (reference is MetadataFileReference)
                {
                    var fileReference = (MetadataFileReference)reference;

                    var assembly = _assemblyLoadContextAccessor
                        .Default
                        .LoadFile(fileReference.Path);

                    return assembly;
                }

                var projectPath = Path.Combine(_path, assemblyName.Name);

                if (!Project.HasProjectFile(projectPath))
                {
                    return null;
                }

                var moduleContext = new ModuleLoaderContext(
                    projectPath,
                    _applicationEnvironment.RuntimeFramework);

                foreach (var lib in moduleContext.LibraryManager.GetLibraries())
                {
                    _libraryManager.AddLibrary(lib);
                }

                var ctx = new CompilationEngineContext(
                    _applicationEnvironment,
                    _runtimeEnvironment,
                    _assemblyLoadContextAccessor.Default,
                    new CompilationCache());

                var engine = new CompilationEngine(ctx);

                var exporter = engine.CreateProjectExporter(
                    moduleContext.Project, moduleContext.TargetFramework, _applicationEnvironment.Configuration);

                var exports = exporter.GetAllExports(moduleContext.Project.Name);

                foreach (var metadataReference in exports.MetadataReferences)
                {
                    _libraryManager.AddMetadataReference(metadataReference);
                }

                //LibraryExport projectExport = exporter.GetExport(moduleContext.Project.Name);
                //IMetadataProjectReference projectRef = (IMetadataProjectReference)projectExport.MetadataReferences.First();

                //string exportDir = Path.Combine(moduleContext.Project.ProjectDirectory, "export");
                //projectRef.EmitAssembly(exportDir);

                //string assemblyPath = Path.Combine(exportDir, moduleContext.Project.Name + ".dll");

                Assembly pluginAssm = engine.LoadProject(
                    moduleContext.Project, moduleContext.FrameworkName, null, _assemblyLoadContextAccessor.Default,
                    new AssemblyName(moduleContext.Project.Name));

                IList<LibraryDependency> flattenedList = moduleContext
                    .Project
                    .Dependencies
                    .SelectMany(Flatten)
                    .Where(x => x.Library.Type == "Package")
                    .Distinct()
                    .ToList();

                //foreach (var dependency in flattenedList)
                //{
                //    foreach (var assemblyToLoad in dependency.Library.Assemblies)
                //    {
                //        Assembly.Load(new AssemblyName(assemblyToLoad));
                //    }
                //}

                return pluginAssm;
            });
        }