public IAssemblyLoadContext Create(IServiceProvider serviceProvider) { var hostContextKey = Tuple.Create("RuntimeLoadContext", _project.Name, _appEnv.Configuration, _appEnv.RuntimeFramework); var appHostContext = _cache.Get<ApplicationHostContext>(hostContextKey, ctx => { var applicationHostContext = new ApplicationHostContext(serviceProvider, _project.ProjectDirectory, packagesDirectory: null, configuration: _appEnv.Configuration, targetFramework: _appEnv.RuntimeFramework, cache: _cache, cacheContextAccessor: _cacheContextAccessor, namedCacheDependencyProvider: _namedDependencyProvider); applicationHostContext.DependencyWalker.Walk(_project.Name, _project.Version, _appEnv.RuntimeFramework); // Watch all projects for project.json changes foreach (var library in applicationHostContext.DependencyWalker.Libraries) { if (string.Equals(library.Type, "Project")) { ctx.Monitor(new FileWriteTimeCacheDependency(library.Path)); } } // Add a cache dependency on restore complete to reevaluate dependencies ctx.Monitor(_namedDependencyProvider.GetNamedDependency(_project.Name + "_Dependencies")); return applicationHostContext; }); var factory = new AssemblyLoadContextFactory(appHostContext.ServiceProvider); return factory.Create(appHostContext.ServiceProvider); }
public AssemblyWalker( FrameworkName framework, ApplicationHostContext hostContext, IDictionary<Library, LibraryDescription> libDictionary, string runtimeFolder) { _framework = framework; _hostContext = hostContext; _runtimeFolder = runtimeFolder; _libDictionary = libDictionary; }
public AssemblyWalker( FrameworkName framework, ApplicationHostContext hostContext, string runtimeFolder, bool showDetails, Reports reports) { _framework = framework; _hostContext = hostContext; _runtimeFolder = runtimeFolder; _showDetails = showDetails; _reports = reports; }
public BuildContext(Project project, FrameworkName targetFramework, string configuration, string outputPath) { _project = project; _targetFramework = targetFramework; _configuration = configuration; _targetFrameworkFolder = VersionUtility.GetShortFrameworkName(_targetFramework); _outputPath = Path.Combine(outputPath, _targetFrameworkFolder); _applicationHostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework); }
private RuntimeLoadContext InitializeProjectLoadContext() { // Create an application host context to use to drive a Load Context used to load Precompilers var context = new ApplicationHostContext { Project = _project, RuntimeIdentifiers = _compilationEngineContext.RuntimeEnvironment.GetAllRuntimeIdentifiers(), TargetFramework = _compilationEngineContext.ApplicationEnvironment.RuntimeFramework }; var libraries = ApplicationHostContext.GetRuntimeLibraries(context); return(new RuntimeLoadContext($"{_project.Name}_build", libraries, _compilationEngine, _compilationEngineContext.DefaultLoadContext)); }
public ModuleLoaderContext( string projectDirectory, FrameworkName targetFramework) { var applicationHostContext = new ApplicationHostContext { ProjectDirectory = projectDirectory, TargetFramework = targetFramework }; ApplicationHostContext.Initialize(applicationHostContext); LibraryManager = applicationHostContext.LibraryManager; Project = applicationHostContext.Project; TargetFramework = applicationHostContext.TargetFramework; }
public LibraryExporter CreateProjectExporter(Project project, FrameworkName targetFramework, string configuration) { // This library manager represents the graph that will be used to resolve // references (compiler /r in csc terms) var context = new ApplicationHostContext { Project = project, TargetFramework = targetFramework }; ApplicationHostContext.Initialize(context); return(new LibraryExporter(context.LibraryManager, this, configuration)); }
public DependencyContext(string projectDirectory, string configuration, FrameworkName targetFramework) { var applicationHostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: projectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework); ProjectResolver = applicationHostContext.ProjectResolver; NuGetDependencyResolver = applicationHostContext.NuGetDependencyProvider; ProjectReferenceDependencyProvider = applicationHostContext.ProjectDepencyProvider; DependencyWalker = applicationHostContext.DependencyWalker; FrameworkName = targetFramework; }
private IAssemblyLoadContextFactory GetRuntimeLoadContextFactory(Runtime.Project project) { var applicationHostContext = new ApplicationHostContext(_hostServices, project.ProjectDirectory, packagesDirectory: null, configuration: _appEnv.Configuration, targetFramework: _appEnv.RuntimeFramework, cache: _cache, cacheContextAccessor: _cacheContextAccessor, namedCacheDependencyProvider: null, loadContextFactory: null); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, _appEnv.RuntimeFramework); return(new AssemblyLoadContextFactory(applicationHostContext.ServiceProvider)); }
private ApplicationHostContext CreateApplicationHostContext() { var accessor = new CacheContextAccessor(); var cache = new Cache(accessor); var hostContext = new ApplicationHostContext( hostServices: null, projectDirectory: _options.Project.ProjectDirectory, packagesDirectory: null, configuration: Configuration, targetFramework: _framework); hostContext.DependencyWalker.Walk(hostContext.Project.Name, hostContext.Project.Version, _framework); return(hostContext); }
public DependencyContext(Runtime.Project project, FrameworkName targetFramework, IEnumerable <string> runtimeIdentifiers) { var applicationHostContext = new ApplicationHostContext { Project = project, TargetFramework = targetFramework, RuntimeIdentifiers = runtimeIdentifiers }; ApplicationHostContext.Initialize(applicationHostContext); FrameworkName = targetFramework; LibraryManager = applicationHostContext.LibraryManager; PackagesDirectory = applicationHostContext.PackagesDirectory; RuntimeIdentifiers = runtimeIdentifiers; }
internal void AddCompiler(string compilerDirectory) { DebugMessage("EdgeAssemblyLoadContext::AddCompiler (CLR) - Adding the compiler in {0}", compilerDirectory); ApplicationHostContext compilerHostContext = new ApplicationHostContext { ProjectDirectory = compilerDirectory, TargetFramework = TargetFrameworkName }; IList <LibraryDescription> libraries = ApplicationHostContext.GetRuntimeLibraries(compilerHostContext); Dictionary <AssemblyName, string> assemblies = PackageDependencyProvider.ResolvePackageAssemblyPaths(libraries); _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries)); DebugMessage("EdgeAssemblyLoadContext::AddCompiler (CLR) - Finished"); }
public BuildContext(ICache cache, ICacheContextAccessor cacheContextAccessor, Runtime.Project project, FrameworkName targetFramework, string configuration, string outputPath) { _project = project; _targetFramework = targetFramework; _configuration = configuration; _targetFrameworkFolder = VersionUtility.GetShortFrameworkName(_targetFramework); _outputPath = Path.Combine(outputPath, _targetFrameworkFolder); _applicationHostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework, cache: cache, cacheContextAccessor: cacheContextAccessor, namedCacheDependencyProvider: new NamedCacheDependencyProvider()); }
private static ApplicationHostContext GetApplicationHostContext(DnxProject project, string configuration, FrameworkName frameworkName) { var cacheKey = Tuple.Create("ApplicationContext", project.Name, configuration, frameworkName); return(cache.Get <ApplicationHostContext>(cacheKey, ctx => { var applicationHostContext = new ApplicationHostContext { ProjectDirectory = project.ProjectDirectory, TargetFramework = frameworkName }; ApplicationHostContext.Initialize(applicationHostContext); return applicationHostContext; })); }
public static void Initialize(IntPtr context, IntPtr exception) { try { DebugMessage("CoreCLREmbedding::Initialize (CLR) - Starting"); RuntimeEnvironment = new EdgeRuntimeEnvironment(Marshal.PtrToStructure <EdgeBootstrapperContext>(context)); Project project; Project.TryGetProject(RuntimeEnvironment.ApplicationDirectory, out project); ApplicationHostContext = new ApplicationHostContext { ProjectDirectory = RuntimeEnvironment.ApplicationDirectory, TargetFramework = TargetFrameworkName, Project = project }; ApplicationEnvironment = new ApplicationEnvironment(ApplicationHostContext.Project, TargetFrameworkName, "Release", null); LoadContextAccessor = new EdgeAssemblyLoadContextAccessor(); EdgeServiceProvider serviceProvider = new EdgeServiceProvider(); serviceProvider.Add(typeof(IRuntimeEnvironment), RuntimeEnvironment); serviceProvider.Add(typeof(IApplicationEnvironment), ApplicationEnvironment); serviceProvider.Add(typeof(IAssemblyLoadContextAccessor), LoadContextAccessor); CallContextServiceLocator.Locator = new EdgeServiceProviderLocator { ServiceProvider = serviceProvider }; PlatformServices.SetDefault(PlatformServices.Create(null, ApplicationEnvironment, RuntimeEnvironment, null, LoadContextAccessor, null)); DebugMessage("CoreCLREmbedding::Initialize (CLR) - Complete"); } catch (Exception e) { DebugMessage("CoreCLREmbedding::Initialize (CLR) - Exception was thrown: {0}", e.Message); V8Type v8Type; Marshal.WriteIntPtr(exception, MarshalCLRToV8(e, out v8Type)); } }
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"); }
private ApplicationHostContext GetApplicationHostContext(Project project, string configuration, FrameworkName frameworkName, bool useRuntimeLoadContextFactory = true) { var cacheKey = Tuple.Create("ApplicationContext", project.Name, configuration, frameworkName); IAssemblyLoadContextFactory loadContextFactory = null; if (useRuntimeLoadContextFactory) { var runtimeApplicationContext = GetApplicationHostContext(project, _appEnv.Configuration, _appEnv.RuntimeFramework, useRuntimeLoadContextFactory: false); loadContextFactory = runtimeApplicationContext.AssemblyLoadContextFactory; } return(_cache.Get <ApplicationHostContext>(cacheKey, ctx => { var applicationHostContext = new ApplicationHostContext(_hostServices, project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: frameworkName, cache: _cache, cacheContextAccessor: _cacheContextAccessor, namedCacheDependencyProvider: _namedDependencyProvider, loadContextFactory: loadContextFactory); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, frameworkName); // Watch all projects for project.json changes foreach (var library in applicationHostContext.DependencyWalker.Libraries) { if (string.Equals(library.Type, "Project")) { ctx.Monitor(new FileWriteTimeCacheDependency(library.Path)); } } // Add a cache dependency on restore complete to reevaluate dependencies ctx.Monitor(_namedDependencyProvider.GetNamedDependency(project.Name + "_RestoreComplete")); return applicationHostContext; })); }
private ApplicationHostContext GetApplicationHostContext(Runtime.Project project, FrameworkName targetFramework, string configuration, CompilationCache cache) { var cacheKey = Tuple.Create("ApplicationContext", project.Name, configuration, targetFramework); return(cache.Cache.Get <ApplicationHostContext>(cacheKey, ctx => { var applicationHostContext = new ApplicationHostContext(hostServices: _hostServices, projectDirectory: project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework, loadContextFactory: GetRuntimeLoadContextFactory(project)); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, targetFramework); return applicationHostContext; })); }
private static ApplicationHostContext GetApplicationHostContext(DnxProject project, string configuration, FrameworkName frameworkName) { var cacheKey = Tuple.Create("ApplicationContext", project.Name, configuration, frameworkName); return(cache.Get <ApplicationHostContext>(cacheKey, ctx => { var applicationHostContext = new ApplicationHostContext(null, project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: frameworkName, cache: cache, cacheContextAccessor: cacheContextAccessor, namedCacheDependencyProvider: namedCacheDependencyProvider); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, frameworkName); return applicationHostContext; })); }
public HashSet<string> GetDependencies(string projectName) { var usedAssemblies = new HashSet<string>(); var projectFolder = Path.Combine(_appbasePath, projectName); var framework = VersionUtility.ParseFrameworkName("aspnetcore50"); var hostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: projectFolder, packagesDirectory: null, configuration: "Debug", targetFramework: framework, cache: _cache, cacheContextAccessor: _accessor, namedCacheDependencyProvider: null); hostContext.DependencyWalker.Walk(hostContext.Project.Name, hostContext.Project.Version, framework); foreach (var library in hostContext.LibraryManager.GetLibraries()) { var isProject = string.Equals(LibraryTypeProject, library.Type, StringComparison.OrdinalIgnoreCase); if (isProject) { continue; } foreach (var loadableAssembly in library.LoadableAssemblies) { usedAssemblies.Add(loadableAssembly.Name); PackageAssembly assembly; if (hostContext.NuGetDependencyProvider.PackageAssemblyLookup.TryGetValue(loadableAssembly.Name, out assembly)) { usedAssemblies.AddRange(WalkAll(assembly.Path)); } } } return usedAssemblies; }
public HashSet <string> GetDependencies(string projectName) { var usedAssemblies = new HashSet <string>(); var projectFolder = Path.Combine(_appbasePath, projectName); var framework = VersionUtility.ParseFrameworkName("aspnetcore50"); var hostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: projectFolder, packagesDirectory: null, configuration: "Debug", targetFramework: framework, cache: _cache, cacheContextAccessor: _accessor, namedCacheDependencyProvider: null); hostContext.DependencyWalker.Walk(hostContext.Project.Name, hostContext.Project.Version, framework); foreach (var library in hostContext.LibraryManager.GetLibraries()) { var isProject = string.Equals(LibraryTypeProject, library.Type, StringComparison.OrdinalIgnoreCase); if (isProject) { continue; } foreach (var loadableAssembly in library.LoadableAssemblies) { usedAssemblies.Add(loadableAssembly.Name); PackageAssembly assembly; if (hostContext.NuGetDependencyProvider.PackageAssemblyLookup.TryGetValue(loadableAssembly.Name, out assembly)) { usedAssemblies.AddRange(WalkAll(assembly.Path)); } } } return(usedAssemblies); }
public IAssemblyLoadContext Create(IServiceProvider serviceProvider) { var hostContextKey = Tuple.Create("RuntimeLoadContext", _project.Name, _appEnv.Configuration, _appEnv.RuntimeFramework); var appHostContext = _compilationFactory.CompilationCache.Cache.Get <ApplicationHostContext>(hostContextKey, ctx => { var applicationHostContext = new ApplicationHostContext(serviceProvider, _project.ProjectDirectory, packagesDirectory: null, configuration: _appEnv.Configuration, targetFramework: _appEnv.RuntimeFramework); applicationHostContext.DependencyWalker.Walk(_project.Name, _project.Version, _appEnv.RuntimeFramework); // Watch all projects for project.json changes foreach (var library in applicationHostContext.DependencyWalker.Libraries) { if (string.Equals(library.Type, "Project")) { ctx.Monitor(new FileWriteTimeCacheDependency(library.Path)); } } // Add a cache dependency on restore complete to reevaluate dependencies ctx.Monitor(_compilationFactory.CompilationCache.NamedCacheDependencyProvider.GetNamedDependency(_project.Name + "_Dependencies")); // Create compilation engine and add it to the services var compilationEngine = _compilationFactory.CreateEngine(new CompilationEngineContext( applicationHostContext.LibraryManager, applicationHostContext.ProjectGraphProvider, NoopWatcher.Instance, applicationHostContext.ServiceProvider, _appEnv.RuntimeFramework, _appEnv.Configuration)); applicationHostContext.AddService(typeof(ICompilationEngine), compilationEngine); return(applicationHostContext); }); var factory = new AssemblyLoadContextFactory(appHostContext.ServiceProvider); return(factory.Create(appHostContext.ServiceProvider)); }
private ApplicationHostContext CreateApplicationHostContext() { var accessor = new CacheContextAccessor(); var cache = new Cache(accessor); var hostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: _options.Project.ProjectDirectory, packagesDirectory: null, configuration: Configuration, targetFramework: _framework, cache: cache, cacheContextAccessor: accessor, namedCacheDependencyProvider: null); hostContext.DependencyWalker.Walk(hostContext.Project.Name, hostContext.Project.Version, _framework); return hostContext; }
public DependencyContext(string projectDirectory, string configuration, FrameworkName targetFramework) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var applicationHostContext = new ApplicationHostContext( hostServices: null, projectDirectory: projectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework); ProjectResolver = applicationHostContext.ProjectResolver; NuGetDependencyResolver = applicationHostContext.NuGetDependencyProvider; ProjectReferenceDependencyProvider = applicationHostContext.ProjectDependencyProvider; DependencyWalker = applicationHostContext.DependencyWalker; FrameworkName = targetFramework; PackagesDirectory = applicationHostContext.PackagesDirectory; }
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); foreach (LibraryDescription libraryDescription in libraries.Where(l => l.Type == LibraryTypes.Package)) { PackageDescription packageDescription = (PackageDescription)libraryDescription; if (packageDescription.Target.CompileTimeAssemblies != null && packageDescription.Target.CompileTimeAssemblies.Count > 0) { CompileAssemblies[libraryDescription.Identity.Name] = Path.Combine(packageDescription.Path, packageDescription.Target.CompileTimeAssemblies[0].Path); } else { CompileAssemblies[libraryDescription.Identity.Name] = Path.Combine(packageDescription.Path, packageDescription.Target.RuntimeAssemblies[0].Path); } } _loaders.Add(new ProjectAssemblyLoader(_loadContextAccessor, compilationEngine, projects.Values)); _loaders.Add(new PackageAssemblyLoader(_loadContextAccessor, assemblies, libraries)); } else { _noProjectJsonFile = true; } DebugMessage("EdgeAssemblyLoadContext::ctor (CLR) - Created the dependency providers for the application"); }
public BuildContext(IServiceProvider hostServices, IApplicationEnvironment appEnv, ICache cache, ICacheContextAccessor cacheContextAccessor, Runtime.Project project, FrameworkName targetFramework, string configuration, string outputPath) { _project = project; _targetFramework = targetFramework; _configuration = configuration; _targetFrameworkFolder = VersionUtility.GetShortFrameworkName(_targetFramework); _outputPath = Path.Combine(outputPath, _targetFrameworkFolder); _hostServices = hostServices; _cache = cache; _cacheContextAccessor = cacheContextAccessor; _appEnv = appEnv; _applicationHostContext = GetApplicationHostContext(project, targetFramework, configuration); }
public DependencyContext(string projectDirectory, string configuration, FrameworkName targetFramework) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var applicationHostContext = new ApplicationHostContext( serviceProvider: null, projectDirectory: projectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework, cache: cache, cacheContextAccessor: cacheContextAccessor, namedCacheDependencyProvider: new NamedCacheDependencyProvider()); ProjectResolver = applicationHostContext.ProjectResolver; NuGetDependencyResolver = applicationHostContext.NuGetDependencyProvider; ProjectReferenceDependencyProvider = applicationHostContext.ProjectDepencyProvider; DependencyWalker = applicationHostContext.DependencyWalker; FrameworkName = targetFramework; PackagesDirectory = applicationHostContext.PackagesDirectory; }
public ModuleLoaderContext( IServiceProvider hostServices, string projectDirectory, string configuration, FrameworkName targetFramework) { var applicationHostContext = new ApplicationHostContext( hostServices: hostServices, projectDirectory: projectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework); DependencyWalker = applicationHostContext.DependencyWalker; FrameworkName = targetFramework; ServiceProvider = applicationHostContext.ServiceProvider; AssemblyLoadContextFactory = applicationHostContext.AssemblyLoadContextFactory; LibraryManager = applicationHostContext.LibraryManager; Project = applicationHostContext.Project; ProjectGraphProvider = applicationHostContext.ProjectGraphProvider; NuGetDependencyProvider = applicationHostContext.NuGetDependencyProvider; Walk(Project.Name, Project.Version); }
public IAssemblyLoadContext Create(IServiceProvider serviceProvider) { var hostContextKey = Tuple.Create("RuntimeLoadContext", _project.Name, _appEnv.Configuration, _appEnv.RuntimeFramework); var appHostContext = _cache.Get <ApplicationHostContext>(hostContextKey, ctx => { var applicationHostContext = new ApplicationHostContext(serviceProvider, _project.ProjectDirectory, packagesDirectory: null, configuration: _appEnv.Configuration, targetFramework: _appEnv.RuntimeFramework, cache: _cache, cacheContextAccessor: _cacheContextAccessor, namedCacheDependencyProvider: _namedDependencyProvider); applicationHostContext.DependencyWalker.Walk(_project.Name, _project.Version, _appEnv.RuntimeFramework); // Watch all projects for project.json changes foreach (var library in applicationHostContext.DependencyWalker.Libraries) { if (string.Equals(library.Type, "Project")) { ctx.Monitor(new FileWriteTimeCacheDependency(library.Path)); } } // Add a cache dependency on restore complete to reevaluate dependencies ctx.Monitor(_namedDependencyProvider.GetNamedDependency(_project.Name + "_Dependencies")); return(applicationHostContext); }); var factory = new AssemblyLoadContextFactory(appHostContext.ServiceProvider); return(factory.Create(appHostContext.ServiceProvider)); }
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); }
private void Initialize(DefaultHostOptions options, IServiceProvider hostServices) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var namedCacheDependencyProvider = new NamedCacheDependencyProvider(); _applicationHostContext = new ApplicationHostContext( hostServices, _projectDirectory, options.PackageDirectory, options.Configuration, _targetFramework, cache, cacheContextAccessor, namedCacheDependencyProvider); Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory); Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory); Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory); _project = _applicationHostContext.Project; if (Project == null) { throw new Exception("Unable to locate " + Project.ProjectFileName); } if (options.WatchFiles) { var watcher = new FileWatcher(_applicationHostContext.RootDirectory); _watcher = watcher; watcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } else { _watcher = NoopWatcher.Instance; } _applicationHostContext.AddService(typeof(IApplicationShutdown), _shutdown); // TODO: Get rid of this and just use the IFileWatcher _applicationHostContext.AddService(typeof(IFileMonitor), _watcher); _applicationHostContext.AddService(typeof(IFileWatcher), _watcher); if (options.CompilationServerPort.HasValue) { // Using this ctor because it works on mono, this is hard coded to ipv4 // right now. Mono will eventually have the dualmode overload var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(new IPEndPoint(IPAddress.Loopback, options.CompilationServerPort.Value)); var networkStream = new NetworkStream(socket); _applicationHostContext.AddService(typeof(IDesignTimeHostCompiler), new DesignTimeHostCompiler(_shutdown, _watcher, networkStream), includeInManifest: false); // Change the project reference provider Project.DefaultLanguageService = new TypeInformation( typeof(DefaultHost).GetTypeInfo().Assembly.GetName().Name, typeof(DesignTimeHostProjectReferenceProvider).FullName); } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; }
private void Initialize(RuntimeOptions options, IServiceProvider hostServices, IAssemblyLoadContextAccessor loadContextAccessor, IFileWatcher fileWatcher) { 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; ValidateMinRuntimeVersion(libraries); if (options.WatchFiles) { fileWatcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } // 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 = (IApplicationEnvironment)hostServices.GetService(typeof(IApplicationEnvironment)); var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, options.Configuration, hostEnvironment); var compilationContext = new CompilationEngineContext( applicationEnvironment, _runtimeEnvironment, loadContextAccessor.Default, new CompilationCache(), fileWatcher); // Compilation services available only for runtime compilation compilationContext.AddCompilationService(typeof(RuntimeOptions), options); compilationContext.AddCompilationService(typeof(IApplicationShutdown), _shutdown); var compilationEngine = new CompilationEngine(compilationContext); // Default services _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment); _serviceProvider.Add(typeof(ILibraryManager), new RuntimeLibraryManager(applicationHostContext)); _serviceProvider.Add(typeof(ILibraryExporter), new RuntimeLibraryExporter(() => compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration))); _serviceProvider.Add(typeof(IApplicationShutdown), _shutdown); if (options.CompilationServerPort.HasValue) { // Change the project reference provider Project.DefaultCompiler = Project.DefaultDesignTimeCompiler; } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; // TODO: Dedupe this logic in the RuntimeLoadContext var projects = libraries.Where(p => p.Type == 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)); _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, assemblies)); _serviceProvider.Add(typeof(ICompilerOptionsProvider), new CompilerOptionsProvider(projects)); AddBreadcrumbs(libraries); }
private void Initialize(RuntimeOptions options, IServiceProvider hostServices, IAssemblyLoadContextAccessor loadContextAccessor, IFileWatcher fileWatcher) { var applicationHostContext = new ApplicationHostContext { ProjectDirectory = _projectDirectory, TargetFramework = _targetFramework }; ApplicationHostContext.Initialize(applicationHostContext); 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); _libraryManager = applicationHostContext.LibraryManager; _project = applicationHostContext.Project; if (options.WatchFiles) { fileWatcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } // 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 = (IApplicationEnvironment)hostServices.GetService(typeof(IApplicationEnvironment)); var applicationEnvironment = new ApplicationEnvironment(Project, _targetFramework, options.Configuration, hostEnvironment); var compilationContext = new CompilationEngineContext(applicationEnvironment, loadContextAccessor.Default, new CompilationCache(), fileWatcher, new ProjectGraphProvider()); // Compilation services available only for runtime compilation compilationContext.AddCompilationService(typeof(RuntimeOptions), options); compilationContext.AddCompilationService(typeof(IApplicationShutdown), _shutdown); var compilationEngine = new CompilationEngine(compilationContext); // Default services _serviceProvider.Add(typeof(IApplicationEnvironment), applicationEnvironment); _serviceProvider.Add(typeof(ILibraryManager), _libraryManager); // TODO: Make this lazy _serviceProvider.Add(typeof(ILibraryExporter), compilationEngine.CreateProjectExporter(Project, _targetFramework, options.Configuration)); _serviceProvider.Add(typeof(IApplicationShutdown), _shutdown); _serviceProvider.Add(typeof(ICompilerOptionsProvider), new CompilerOptionsProvider(_libraryManager)); if (options.CompilationServerPort.HasValue) { // Change the project reference provider Project.DefaultCompiler = Project.DefaultDesignTimeCompiler; } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; // Configure Assembly loaders _loaders.Add(new ProjectAssemblyLoader( loadContextAccessor, compilationEngine, _libraryManager)); _loaders.Add(new PackageAssemblyLoader(loadContextAccessor, _libraryManager)); }
public void ApplicationHostContext_SelectsRuntimeIndependentTargetIfNoRuntimeIdsProvided() { // Arrange var ahc = new ApplicationHostContext() { Project = CreateDummyProject(), TargetFramework = Dnx451, LockFile = new LockFile() { Version = Constants.LockFileVersion, Targets = new List<LockFileTarget>() { new LockFileTarget() { TargetFramework = Dnx451, RuntimeIdentifier = string.Empty, Libraries = new List<LockFileTargetLibrary>() { new LockFileTargetLibrary() { Name = "NoRuntime", Version = new SemanticVersion(1, 0, 0, 0) } } }, new LockFileTarget() { TargetFramework = Dnx451, RuntimeIdentifier = "win7-x64", Libraries = new List<LockFileTargetLibrary>() { new LockFileTargetLibrary() { Name = "Runtime.win7-x64", Version = new SemanticVersion(1, 0, 0, 0) } } } }, PackageLibraries = new List<LockFilePackageLibrary>() { new LockFilePackageLibrary() { Name = "NoRuntime", Version = new SemanticVersion(1, 0, 0, 0) }, new LockFilePackageLibrary() { Name = "Runtime.win7-x64", Version = new SemanticVersion(1, 0, 0, 0) } } } }; // Act var libs = ApplicationHostContext.GetRuntimeLibraries(ahc); // Assert Assert.Equal(new[] { "DummyProject/1.0.0", "NoRuntime/1.0.0" }, libs.Select(l => $"{l.Identity.Name}/{l.Identity.Version}").ToArray()); }
private void Initialize(DefaultHostOptions options, IServiceProvider hostServices) { var cacheContextAccessor = new CacheContextAccessor(); var cache = new Cache(cacheContextAccessor); var namedCacheDependencyProvider = new NamedCacheDependencyProvider(); _applicationHostContext = new ApplicationHostContext( hostServices, _projectDirectory, options.PackageDirectory, options.Configuration, _targetFramework, cache, cacheContextAccessor, namedCacheDependencyProvider); Logger.TraceInformation("[{0}]: Project path: {1}", GetType().Name, _projectDirectory); Logger.TraceInformation("[{0}]: Project root: {1}", GetType().Name, _applicationHostContext.RootDirectory); Logger.TraceInformation("[{0}]: Packages path: {1}", GetType().Name, _applicationHostContext.PackagesDirectory); _project = _applicationHostContext.Project; if (Project == null) { throw new Exception("Unable to locate " + Project.ProjectFileName); } if (options.WatchFiles) { var watcher = new FileWatcher(_applicationHostContext.RootDirectory); _watcher = watcher; watcher.OnChanged += _ => { _shutdown.RequestShutdownWaitForDebugger(); }; } else { _watcher = NoopWatcher.Instance; } _applicationHostContext.AddService(typeof(IApplicationShutdown), _shutdown); _applicationHostContext.AddService(typeof(IRuntimeOptions), options); // TODO: Get rid of this and just use the IFileWatcher _applicationHostContext.AddService(typeof(IFileMonitor), _watcher); _applicationHostContext.AddService(typeof(IFileWatcher), _watcher); if (options.CompilationServerPort.HasValue) { // Change the project reference provider Project.DefaultCompiler = Project.DefaultDesignTimeCompiler; } CallContextServiceLocator.Locator.ServiceProvider = ServiceProvider; }
private IAssemblyLoadContextFactory GetRuntimeLoadContextFactory(Runtime.Project project) { var applicationHostContext = new ApplicationHostContext(_hostServices, project.ProjectDirectory, packagesDirectory: null, configuration: _appEnv.Configuration, targetFramework: _appEnv.RuntimeFramework, cache: _cache, cacheContextAccessor: _cacheContextAccessor, namedCacheDependencyProvider: null, loadContextFactory: null); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, _appEnv.RuntimeFramework); return new AssemblyLoadContextFactory(applicationHostContext.ServiceProvider); }
private ApplicationHostContext GetApplicationHostContext(Runtime.Project project, FrameworkName targetFramework, string configuration) { var cacheKey = Tuple.Create("ApplicationContext", project.Name, configuration, targetFramework); return _cache.Get<ApplicationHostContext>(cacheKey, ctx => { var applicationHostContext = new ApplicationHostContext(serviceProvider: _hostServices, projectDirectory: project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: targetFramework, cache: _cache, cacheContextAccessor: _cacheContextAccessor, namedCacheDependencyProvider: null, loadContextFactory: GetRuntimeLoadContextFactory(project)); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, targetFramework); return applicationHostContext; }); }
public void ApplicationHostContext_SelectsRuntimeIndependentTargetIfNoRuntimeIdsProvided() { // Arrange var ahc = new ApplicationHostContext() { Project = CreateDummyProject(), TargetFramework = Dnx451, LockFile = new LockFile() { Version = Constants.LockFileVersion, Targets = new List <LockFileTarget>() { new LockFileTarget() { TargetFramework = Dnx451, RuntimeIdentifier = string.Empty, Libraries = new List <LockFileTargetLibrary>() { new LockFileTargetLibrary() { Name = "NoRuntime", Version = new SemanticVersion(1, 0, 0, 0) } } }, new LockFileTarget() { TargetFramework = Dnx451, RuntimeIdentifier = "win7-x64", Libraries = new List <LockFileTargetLibrary>() { new LockFileTargetLibrary() { Name = "Runtime.win7-x64", Version = new SemanticVersion(1, 0, 0, 0) } } } }, PackageLibraries = new List <LockFilePackageLibrary>() { new LockFilePackageLibrary() { Name = "NoRuntime", Version = new SemanticVersion(1, 0, 0, 0) }, new LockFilePackageLibrary() { Name = "Runtime.win7-x64", Version = new SemanticVersion(1, 0, 0, 0) } } } }; // Act var libs = ApplicationHostContext.GetRuntimeLibraries(ahc); // Assert Assert.Equal(new[] { "DummyProject/1.0.0", "NoRuntime/1.0.0" }, libs.Select(l => $"{l.Identity.Name}/{l.Identity.Version}").ToArray()); }
private static ApplicationHostContext GetApplicationHostContext(DnxProject project, string configuration, FrameworkName frameworkName) { var cacheKey = Tuple.Create("ApplicationContext", project.Name, configuration, frameworkName); return cache.Get<ApplicationHostContext>(cacheKey, ctx => { var applicationHostContext = new ApplicationHostContext(null, project.ProjectDirectory, packagesDirectory: null, configuration: configuration, targetFramework: frameworkName, cache: cache, cacheContextAccessor: cacheContextAccessor, namedCacheDependencyProvider: namedCacheDependencyProvider); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, frameworkName); return applicationHostContext; }); }
public DependencyListOperation(DependencyListOptions options, FrameworkName framework) { _options = options; _framework = framework; _hostContext = CreateApplicationHostContext(); }
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)); var cacheContextAccessor = (ICacheContextAccessor)_serviceProvider.GetService(typeof(ICacheContextAccessor)); var namedCacheDependencyProvider = (INamedCacheDependencyProvider)_serviceProvider.GetService(typeof(INamedCacheDependencyProvider)); var loadContextFactory = (IAssemblyLoadContextFactory)_serviceProvider.GetService(typeof(IAssemblyLoadContextFactory)); return cache.Get<ILibraryExport>(key, ctx => { 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.CompilerServices?.ProjectCompiler ?? Project.DefaultCompiler; // Find the default project exporter var projectCompiler = _projectCompilers.GetOrAdd(provider, typeInfo => { return CompilerServices.CreateService<IProjectCompiler>(_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>(() => { // TODO: Cache? var context = new ApplicationHostContext(_serviceProvider, project.ProjectDirectory, packagesDirectory: null, configuration: target.Configuration, targetFramework: target.TargetFramework, cache: cache, cacheContextAccessor: cacheContextAccessor, namedCacheDependencyProvider: namedCacheDependencyProvider, loadContextFactory: loadContextFactory); context.DependencyWalker.Walk(project.Name, project.Version, target.TargetFramework); return ProjectExportProviderHelper.GetExportsRecursive( cache, context.LibraryManager, context.LibraryExportProvider, target, dependenciesOnly: true); }); // Resolve the project export IMetadataProjectReference projectReference = projectCompiler.CompileProject( project, target, () => 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); }); }
private State Initialize(string appPath, string configuration, bool triggerBuildOutputs) { var state = new State { Frameworks = new List <FrameworkData>(), Projects = new List <ProjectInfo>() }; Project project; if (!Project.TryGetProject(appPath, out project)) { throw new InvalidOperationException(string.Format("Unable to find project.json in '{0}'", appPath)); } if (triggerBuildOutputs) { // Trigger the build outputs for this project _namedDependencyProvider.Trigger(project.Name + "_BuildOutputs"); } state.Name = project.Name; state.Configurations = project.GetConfigurations().ToList(); state.Commands = project.Commands; var frameworks = new List <FrameworkName>( project.GetTargetFrameworks() .Select(tf => tf.FrameworkName)); if (!frameworks.Any()) { frameworks.Add(VersionUtility.ParseFrameworkName("aspnet50")); } var appHostContextCache = new Dictionary <Tuple <string, FrameworkName>, ApplicationHostContext>(); // We need to create an app env for the design time host's target framework var runtimeApplicationHostContext = new ApplicationHostContext(_hostServices, appPath, packagesDirectory: null, configuration: _appEnv.Configuration, targetFramework: _appEnv.RuntimeFramework, cache: _cache, cacheContextAccessor: _cacheContextAccessor, namedCacheDependencyProvider: _namedDependencyProvider); runtimeApplicationHostContext.DependencyWalker.Walk(project.Name, project.Version, _appEnv.RuntimeFramework); var runtimeAppHostContextCacheKey = Tuple.Create(_appEnv.Configuration, _appEnv.RuntimeFramework); // TODO: Move this caching to the ICache appHostContextCache[runtimeAppHostContextCacheKey] = runtimeApplicationHostContext; foreach (var frameworkName in frameworks) { var cacheKey = Tuple.Create(configuration, frameworkName); ApplicationHostContext applicationHostContext; if (!appHostContextCache.TryGetValue(cacheKey, out applicationHostContext)) { applicationHostContext = new ApplicationHostContext(_hostServices, appPath, packagesDirectory: null, configuration: configuration, targetFramework: frameworkName, cache: _cache, cacheContextAccessor: _cacheContextAccessor, namedCacheDependencyProvider: _namedDependencyProvider, loadContextFactory: runtimeApplicationHostContext.AssemblyLoadContextFactory); applicationHostContext.DependencyWalker.Walk(project.Name, project.Version, frameworkName); appHostContextCache[cacheKey] = applicationHostContext; } var libraryManager = applicationHostContext.LibraryManager; var metadataProvider = applicationHostContext.CreateInstance <ProjectMetadataProvider>(); var frameworkResolver = applicationHostContext.FrameworkReferenceResolver; var metadata = metadataProvider.GetProjectMetadata(project.Name); var dependencies = applicationHostContext.DependencyWalker .Libraries .Select(CreateDependencyDescription) .ToDictionary(d => d.Name); var projectReferences = applicationHostContext.DependencyWalker .Libraries .Where(d => string.Equals(d.Type, "Project") && !string.Equals(d.Identity.Name, project.Name)) .Select(d => new ProjectReference { Framework = new FrameworkData { ShortName = VersionUtility.GetShortFrameworkName(d.Framework), FrameworkName = d.Framework.ToString(), FriendlyName = frameworkResolver.GetFriendlyFrameworkName(d.Framework) }, Path = d.Path }) .ToList(); var frameworkData = new FrameworkData { ShortName = VersionUtility.GetShortFrameworkName(frameworkName), FrameworkName = frameworkName.ToString(), FriendlyName = frameworkResolver.GetFriendlyFrameworkName(frameworkName), RedistListPath = frameworkResolver.GetFrameworkRedistListPath(frameworkName) }; state.Frameworks.Add(frameworkData); var projectInfo = new ProjectInfo() { Path = appPath, Configuration = configuration, TargetFramework = frameworkData, FrameworkName = frameworkName, // TODO: This shouldn't be roslyn specific compilation options CompilationSettings = project.GetCompilationSettings(frameworkName, configuration), Dependencies = dependencies, ProjectReferences = projectReferences, Metadata = metadata, Output = new ProjectOutput() }; var export = libraryManager.GetLibraryExport(project.Name); var projectReference = export.MetadataReferences.OfType <IMetadataProjectReference>() .First(); var embeddedReferences = export.MetadataReferences.OfType <IMetadataEmbeddedReference>().Select(r => { return(new { Name = r.Name, Bytes = r.Contents }); }) .ToDictionary(a => a.Name, a => a.Bytes); var engine = new NonLoadingLoadContext(); if (!metadata.Errors.Any()) { projectReference.Load(engine); } projectInfo.Output.AssemblyBytes = engine.AssemblyBytes ?? new byte[0]; projectInfo.Output.PdbBytes = engine.PdbBytes ?? new byte[0]; projectInfo.Output.AssemblyPath = engine.AssemblyPath; projectInfo.Output.EmbeddedReferences = embeddedReferences; state.Projects.Add(projectInfo); if (state.ProjectSearchPaths == null) { state.ProjectSearchPaths = applicationHostContext.ProjectResolver.SearchPaths.ToList(); } if (state.GlobalJsonPath == null) { GlobalSettings settings; if (GlobalSettings.TryGetGlobalSettings(applicationHostContext.RootDirectory, out settings)) { state.GlobalJsonPath = settings.FilePath; } } } return(state); }