public ApplicationHostPlatformServices(PlatformServices previous, 
                                        ApplicationEnvironment applicationEnvironment, 
                                        RuntimeLibraryManager runtimeLibraryManager)
 {
     _previous = previous;
     LibraryManager = runtimeLibraryManager;
     Application = applicationEnvironment;
 }
示例#2
0
 public ApplicationHostPlatformServices(PlatformServices previous,
                                        ApplicationEnvironment applicationEnvironment,
                                        RuntimeLibraryManager runtimeLibraryManager)
 {
     _previous      = previous;
     LibraryManager = runtimeLibraryManager;
     Application    = applicationEnvironment;
 }
示例#3
0
        private void Initialize(DefaultHostOptions options, IAssemblyLoadContextAccessor loadContextAccessor)
        {
            var applicationHostContext = new ApplicationHostContext
            {
                ProjectDirectory   = _projectDirectory,
                RuntimeIdentifiers = _runtimeEnvironment.GetAllRuntimeIdentifiers(),
                TargetFramework    = _targetFramework
            };

            var libraries = ApplicationHostContext.GetRuntimeLibraries(applicationHostContext, throwOnInvalidLockFile: true);

            Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, applicationHostContext.ProjectDirectory);
            Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, applicationHostContext.RootDirectory);
            Logger.TraceInformation("[{0}]: Project configuration: {1}", GetType().Name, options.Configuration);
            Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, applicationHostContext.PackagesDirectory);

            _applicationHostContext = applicationHostContext;

            _project = applicationHostContext.Project;

#if FEATURE_DNX_MIN_VERSION_CHECK
            ValidateMinRuntimeVersion(libraries);
#endif

            // Create a new Application Environment for running the app. It needs a reference to the Host's application environment
            // (if any), which we can get from the service provider we were given.
            // If this is null (i.e. there is no Host Application Environment), that's OK, the Application Environment we are creating
            // will just have it's own independent set of global data.
            var hostEnvironment        = PlatformServices.Default.Application;
            var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, hostEnvironment);

            var compilationContext = new CompilationEngineContext(
                applicationEnvironment,
                _runtimeEnvironment,
                loadContextAccessor.Default,
                new CompilationCache());

            var compilationEngine      = new CompilationEngine(compilationContext);
            var runtimeLibraryExporter = new RuntimeLibraryExporter(() => compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration));

            var runtimeLibraryManager = new RuntimeLibraryManager(applicationHostContext);

            // Default services
            _serviceProvider.Add(typeof(ILibraryExporter), runtimeLibraryExporter);
            _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment);
            _serviceProvider.Add(typeof(IRuntimeEnvironment), PlatformServices.Default.Runtime);
            _serviceProvider.Add(typeof(ILibraryManager), runtimeLibraryManager);
            _serviceProvider.Add(typeof(IAssemblyLoadContextAccessor), PlatformServices.Default.AssemblyLoadContextAccessor);
            _serviceProvider.Add(typeof(IAssemblyLoaderContainer), PlatformServices.Default.AssemblyLoaderContainer);

            PlatformServices.SetDefault(new ApplicationHostPlatformServices(PlatformServices.Default, applicationEnvironment, runtimeLibraryManager));

            if (options.CompilationServerPort.HasValue)
            {
                // Change the project reference provider
                Project.DefaultCompiler        = Project.DefaultDesignTimeCompiler;
                Project.DesignTimeCompilerPort = options.CompilationServerPort.Value;
            }

            // TODO: Dedupe this logic in the RuntimeLoadContext
            var projects = libraries.Where(p => p.Type == Runtime.LibraryTypes.Project)
                           .ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p);

            var assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries);

            // Configure Assembly loaders
            _loaders.Add(new ProjectAssemblyLoader(loadContextAccessor, compilationEngine, projects.Values, options.Configuration));
            _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, assemblies, libraries));

            var compilerOptionsProvider = new CompilerOptionsProvider(projects);

            _serviceProvider.Add(typeof(ICompilerOptionsProvider), compilerOptionsProvider);

            CompilationServices.SetDefault(
                CompilationServices.Create(
                    libraryExporter: runtimeLibraryExporter,
                    compilerOptionsProvider: compilerOptionsProvider
                    )
                );

#if DNX451
            PackageDependencyProvider.EnableLoadingNativeLibraries(libraries);
#endif
            AddBreadcrumbs(libraries);
        }
示例#4
0
        private void Initialize(DefaultHostOptions options, IAssemblyLoadContextAccessor loadContextAccessor)
        {
            var applicationHostContext = new ApplicationHostContext
            {
                ProjectDirectory = _projectDirectory,
                RuntimeIdentifiers = _runtimeEnvironment.GetAllRuntimeIdentifiers(),
                TargetFramework = _targetFramework
            };

            var libraries = ApplicationHostContext.GetRuntimeLibraries(applicationHostContext, throwOnInvalidLockFile: true);

            Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, applicationHostContext.ProjectDirectory);
            Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, applicationHostContext.RootDirectory);
            Logger.TraceInformation("[{0}]: Project configuration: {1}", GetType().Name, options.Configuration);
            Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, applicationHostContext.PackagesDirectory);

            _applicationHostContext = applicationHostContext;

            _project = applicationHostContext.Project;

#if FEATURE_DNX_MIN_VERSION_CHECK
            ValidateMinRuntimeVersion(libraries);
#endif

            // Create a new Application Environment for running the app. It needs a reference to the Host's application environment
            // (if any), which we can get from the service provider we were given.
            // If this is null (i.e. there is no Host Application Environment), that's OK, the Application Environment we are creating
            // will just have it's own independent set of global data.
            var hostEnvironment = PlatformServices.Default.Application;
            var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, hostEnvironment);

            var compilationContext = new CompilationEngineContext(
                applicationEnvironment,
                _runtimeEnvironment,
                loadContextAccessor.Default,
                new CompilationCache());

            var compilationEngine = new CompilationEngine(compilationContext);
            var runtimeLibraryExporter = new RuntimeLibraryExporter(() => compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration));

            var runtimeLibraryManager = new RuntimeLibraryManager(applicationHostContext);

            // Default services
            _serviceProvider.Add(typeof(ILibraryExporter), runtimeLibraryExporter);
            _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment);
            _serviceProvider.Add(typeof(IRuntimeEnvironment), PlatformServices.Default.Runtime);
            _serviceProvider.Add(typeof(ILibraryManager), runtimeLibraryManager);
            _serviceProvider.Add(typeof(IAssemblyLoadContextAccessor), PlatformServices.Default.AssemblyLoadContextAccessor);
            _serviceProvider.Add(typeof(IAssemblyLoaderContainer), PlatformServices.Default.AssemblyLoaderContainer);
            
            PlatformServices.SetDefault(new ApplicationHostPlatformServices(PlatformServices.Default, applicationEnvironment, runtimeLibraryManager));

            if (options.CompilationServerPort.HasValue)
            {
                // Change the project reference provider
                Project.DefaultCompiler = Project.DefaultDesignTimeCompiler;
                Project.DesignTimeCompilerPort = options.CompilationServerPort.Value;
            }

            // TODO: Dedupe this logic in the RuntimeLoadContext
            var projects = libraries.Where(p => p.Type == Runtime.LibraryTypes.Project)
                                    .ToDictionary(p => p.Identity.Name, p => (ProjectDescription)p);

            var assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries);

            // Configure Assembly loaders
            _loaders.Add(new ProjectAssemblyLoader(loadContextAccessor, compilationEngine, projects.Values, options.Configuration));
            _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, assemblies, libraries));

            var compilerOptionsProvider = new CompilerOptionsProvider(projects);

            _serviceProvider.Add(typeof(ICompilerOptionsProvider), compilerOptionsProvider);

            CompilationServices.SetDefault(
                    CompilationServices.Create(
                            libraryExporter: runtimeLibraryExporter,
                            compilerOptionsProvider: compilerOptionsProvider
                        )
                );

#if DNX451
            PackageDependencyProvider.EnableLoadingNativeLibraries(libraries);
#endif
            AddBreadcrumbs(libraries);
        }