public DesignTimeAssemblyLoadContextFactory(Project project,
                                             IApplicationEnvironment appEnv,
                                             CompilationEngineFactory compilationFactory)
 {
     _project = project;
     _appEnv = appEnv;
     _compilationFactory = compilationFactory;
 }
예제 #2
0
        public bool Build()
        {
            var projectFilesFinder = new Matcher();

            // Resolve all the project names
            var projectFilesToBuild = new List<string>();
            foreach(var pattern in _buildOptions.ProjectPatterns)
            {
                if (pattern.Contains("*"))
                {
                    // Requires globbing
                    projectFilesFinder.AddInclude(NormalizeGlobbingPattern(pattern));
                }
                else
                {
                    projectFilesToBuild.Add(pattern);
                }
            }

            var rootDirectory = Directory.GetCurrentDirectory();
            var patternSearchFolder = new DirectoryInfoWrapper(new DirectoryInfo(rootDirectory));
            var globbingProjects = projectFilesFinder.Execute(patternSearchFolder).Files.Select(file =>
                Path.Combine(rootDirectory, file));
            projectFilesToBuild.AddRange(globbingProjects);

            var sw = Stopwatch.StartNew();

            _compilationEngine = new CompilationEngineFactory(new CompilationCache());

            var globalSucess = true;
            foreach (var project in projectFilesToBuild)
            {
                var buildSuccess = BuildInternal(project);
                globalSucess &= buildSuccess;
            }

            _buildOptions.Reports.Information.WriteLine($"Total build time elapsed: { sw.Elapsed }");
            _buildOptions.Reports.Information.WriteLine($"Total projects built: { projectFilesToBuild.Count }");

            return globalSucess;
        }
예제 #3
0
        public Assembly Load(AssemblyName assemblyName)
        {
            Project project;
            string name = assemblyName.FullName;
            if (!Project.TryGetProject(_virtualPathProvider.Combine(_path, name), out project)) {
                return null;
            }

            return _cache.Get<Assembly>(assemblyName.Name, cacheContext => {
                var target = new CompilationTarget(
                    name,
                    project.GetTargetFramework(_applicationEnvironment.RuntimeFramework).FrameworkName,
                    _applicationEnvironment.Configuration,
                    null);

                _moduleContext = new ModuleLoaderContext(
                    _serviceProvider,
                    project.ProjectDirectory,
                    target.Configuration,
                    target.TargetFramework);

                foreach (var lib in _moduleContext.DependencyWalker.Libraries) {
                    _libraryManager.AddLibrary(lib.ToLibrary());
                }

                var compilationEngineFactory = new CompilationEngineFactory(
                    NoopWatcher.Instance, new CompilationCache());

                var engine = compilationEngineFactory.CreateEngine(new CompilationEngineContext(
                    _moduleContext.LibraryManager,
                    _moduleContext.ProjectGraphProvider,
                    _moduleContext.ServiceProvider,
                    target.TargetFramework,
                    target.Configuration));

                _packageAssemblyLookup.AddLoader(
                    _moduleContext.NuGetDependencyProvider);

                var p = engine.LoadProject(project, null, _assemblyLoadContextAccessor.Default);

                var exports = engine.RootLibraryExporter.GetExport(project.Name);
                foreach (var metadataReference in exports.MetadataReferences) {
                    _libraryManager.AddMetadataReference(metadataReference);
                }

                return p;
            });
        }