public ReferenceAssemblyDependencyResolver(FrameworkReferenceResolver frameworkReferenceResolver) { FrameworkResolver = frameworkReferenceResolver; }
public ApplicationHostContext(IServiceProvider serviceProvider, string projectDirectory, string packagesDirectory, string configuration, FrameworkName targetFramework, ICache cache, ICacheContextAccessor cacheContextAccessor, INamedCacheDependencyProvider namedCacheDependencyProvider, IAssemblyLoadContextFactory loadContextFactory = null) { ProjectDirectory = projectDirectory; Configuration = configuration; RootDirectory = Runtime.ProjectResolver.ResolveRootDirectory(ProjectDirectory); ProjectResolver = new ProjectResolver(ProjectDirectory, RootDirectory); FrameworkReferenceResolver = new FrameworkReferenceResolver(); _serviceProvider = new ServiceProvider(serviceProvider); PackagesDirectory = packagesDirectory ?? NuGetDependencyResolver.ResolveRepositoryPath(RootDirectory); var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(FrameworkReferenceResolver); NuGetDependencyProvider = new NuGetDependencyResolver(PackagesDirectory, RootDirectory); var gacDependencyResolver = new GacDependencyResolver(); ProjectDepencyProvider = new ProjectReferenceDependencyProvider(ProjectResolver); var unresolvedDependencyProvider = new UnresolvedDependencyProvider(); DependencyWalker = new DependencyWalker(new IDependencyProvider[] { ProjectDepencyProvider, NuGetDependencyProvider, referenceAssemblyDependencyResolver, gacDependencyResolver, unresolvedDependencyProvider }); LibraryExportProvider = new CompositeLibraryExportProvider(new ILibraryExportProvider[] { new ProjectLibraryExportProvider(ProjectResolver, ServiceProvider), referenceAssemblyDependencyResolver, gacDependencyResolver, NuGetDependencyProvider }); LibraryManager = new LibraryManager(targetFramework, configuration, DependencyWalker, LibraryExportProvider, cache); AssemblyLoadContextFactory = loadContextFactory ?? new AssemblyLoadContextFactory(ServiceProvider); // Default services _serviceProvider.Add(typeof(IApplicationEnvironment), new ApplicationEnvironment(Project, targetFramework, configuration)); _serviceProvider.Add(typeof(ILibraryExportProvider), LibraryExportProvider, includeInManifest: false); _serviceProvider.Add(typeof(IProjectResolver), ProjectResolver); _serviceProvider.Add(typeof(IFileWatcher), NoopWatcher.Instance); _serviceProvider.Add(typeof(NuGetDependencyResolver), NuGetDependencyProvider, includeInManifest: false); _serviceProvider.Add(typeof(ProjectReferenceDependencyProvider), ProjectDepencyProvider, includeInManifest: false); _serviceProvider.Add(typeof(ILibraryManager), LibraryManager); _serviceProvider.Add(typeof(ICache), cache); _serviceProvider.Add(typeof(ICacheContextAccessor), cacheContextAccessor); _serviceProvider.Add(typeof(INamedCacheDependencyProvider), namedCacheDependencyProvider, includeInManifest: false); _serviceProvider.Add(typeof(IAssemblyLoadContextFactory), AssemblyLoadContextFactory); }
public ApplicationHostContext(IServiceProvider serviceProvider, string projectDirectory, string packagesDirectory, string configuration, FrameworkName targetFramework, ICache cache, ICacheContextAccessor cacheContextAccessor, INamedCacheDependencyProvider namedCacheDependencyProvider, IAssemblyLoadContextFactory loadContextFactory = null, bool skipLockFileValidation = false) { ProjectDirectory = projectDirectory; Configuration = configuration; RootDirectory = Runtime.ProjectResolver.ResolveRootDirectory(ProjectDirectory); ProjectResolver = new ProjectResolver(ProjectDirectory, RootDirectory); FrameworkReferenceResolver = new FrameworkReferenceResolver(); _serviceProvider = new ServiceProvider(serviceProvider); PackagesDirectory = packagesDirectory ?? NuGetDependencyResolver.ResolveRepositoryPath(RootDirectory); var referenceAssemblyDependencyResolver = new ReferenceAssemblyDependencyResolver(FrameworkReferenceResolver); NuGetDependencyProvider = new NuGetDependencyResolver(new PackageRepository(PackagesDirectory)); var gacDependencyResolver = new GacDependencyResolver(); ProjectDepencyProvider = new ProjectReferenceDependencyProvider(ProjectResolver); var unresolvedDependencyProvider = new UnresolvedDependencyProvider(); var projectName = PathUtility.GetDirectoryName(ProjectDirectory); Project project; if (ProjectResolver.TryResolveProject(projectName, out project)) { Project = project; } else { throw new InvalidOperationException( string.Format("Unable to resolve project '{0}' from {1}", projectName, ProjectDirectory)); } var projectLockJsonPath = Path.Combine(ProjectDirectory, LockFileFormat.LockFileName); var lockFileExists = File.Exists(projectLockJsonPath); var validLockFile = false; if (lockFileExists) { var lockFileFormat = new LockFileFormat(); var lockFile = lockFileFormat.Read(projectLockJsonPath); validLockFile = lockFile.IsValidForProject(Project); if (validLockFile || skipLockFileValidation) { NuGetDependencyProvider.ApplyLockFile(lockFile); DependencyWalker = new DependencyWalker(new IDependencyProvider[] { ProjectDepencyProvider, NuGetDependencyProvider, referenceAssemblyDependencyResolver, gacDependencyResolver, unresolvedDependencyProvider }); } } if ((!validLockFile && !skipLockFileValidation) || !lockFileExists) { // We don't add NuGetDependencyProvider to DependencyWalker // It will leave all NuGet packages unresolved and give error message asking users to run "dnu restore" DependencyWalker = new DependencyWalker(new IDependencyProvider[] { ProjectDepencyProvider, referenceAssemblyDependencyResolver, gacDependencyResolver, unresolvedDependencyProvider }); } LibraryExportProvider = new CompositeLibraryExportProvider(new ILibraryExportProvider[] { new ProjectLibraryExportProvider(ProjectResolver, ServiceProvider), referenceAssemblyDependencyResolver, gacDependencyResolver, NuGetDependencyProvider }); LibraryManager = new LibraryManager(targetFramework, configuration, DependencyWalker, LibraryExportProvider, cache); AssemblyLoadContextFactory = loadContextFactory ?? new RuntimeLoadContextFactory(ServiceProvider); namedCacheDependencyProvider = namedCacheDependencyProvider ?? NamedCacheDependencyProvider.Empty; // Default services _serviceProvider.Add(typeof(IApplicationEnvironment), new ApplicationEnvironment(Project, targetFramework, configuration)); _serviceProvider.Add(typeof(IFileWatcher), NoopWatcher.Instance); _serviceProvider.Add(typeof(ILibraryManager), LibraryManager); // Not exposed to the application layer _serviceProvider.Add(typeof(ILibraryExportProvider), LibraryExportProvider, includeInManifest: false); _serviceProvider.Add(typeof(IProjectResolver), ProjectResolver, includeInManifest: false); _serviceProvider.Add(typeof(NuGetDependencyResolver), NuGetDependencyProvider, includeInManifest: false); _serviceProvider.Add(typeof(ProjectReferenceDependencyProvider), ProjectDepencyProvider, includeInManifest: false); _serviceProvider.Add(typeof(ICache), cache, includeInManifest: false); _serviceProvider.Add(typeof(ICacheContextAccessor), cacheContextAccessor, includeInManifest: false); _serviceProvider.Add(typeof(INamedCacheDependencyProvider), namedCacheDependencyProvider, includeInManifest: false); _serviceProvider.Add(typeof(IAssemblyLoadContextFactory), AssemblyLoadContextFactory, includeInManifest: false); var compilerOptionsProvider = new CompilerOptionsProvider(ProjectResolver); _serviceProvider.Add(typeof(ICompilerOptionsProvider), compilerOptionsProvider); }