Exemple #1
0
        private void ProcessPatterns()
        {
            // Get the assemblies local to the entry assembly
            _assemblies.AddRange(_fileSystem
                                 .GetFiles(_entryAssemblyDirectory, _patterns)
                                 .Where(x => x.Path.Extension == ".dll" || x.Path.Extension == ".exe")
                                 .Select(x => x.Path.FullPath));

            // Get requested assemblies from the build root
            _assemblies.AddRange(_fileSystem
                                 .GetFiles(_patterns)
                                 .Where(x => x.Path.Extension == ".dll" || x.Path.Extension == ".exe")
                                 .Select(x => x.Path.FullPath));
        }
Exemple #2
0
        private void LoadAssembliesByPath()
        {
            // Get path to all assemblies (except those specified by name)
            string        entryAssemblyLocation = Assembly.GetEntryAssembly()?.Location;
            DirectoryPath entryAssemblyPath     = entryAssemblyLocation == null
                ? new DirectoryPath(Environment.CurrentDirectory)
                : new FilePath(entryAssemblyLocation).Directory;
            IDirectory      entryAssemblyDirectory = _fileSystem.GetDirectory(entryAssemblyPath);
            List <FilePath> assemblyPaths          = _fileSystem
                                                     .GetFiles(entryAssemblyDirectory, _patterns)
                                                     .Where(x => x.Path.Extension == ".dll" || x.Path.Extension == ".exe")
                                                     .Select(x => x.Path)
                                                     .ToList();

            // Add all paths to the PrivateBinPath search location (to ensure they load in the default context)
            AppDomain.CurrentDomain.SetupInformation.PrivateBinPath =
                string.Join(";",
                            new[] { AppDomain.CurrentDomain.SetupInformation.PrivateBinPath }
                            .Concat(assemblyPaths.Select(x => x.Directory.FullPath).Distinct())
                            .Distinct());

            foreach (string assemblyPath in assemblyPaths.Select(x => x.FullPath).Distinct())
            {
                try
                {
                    using (Trace.WithIndent().Verbose("Loading assembly file {0}", assemblyPath))
                    {
                        AssemblyName assemblyName = AssemblyName.GetAssemblyName(assemblyPath);
                        Assembly     assembly     = Assembly.Load(assemblyName);
                        if (!_assemblies.Add(assembly))
                        {
                            Trace.Verbose("Skipping assembly file {0} because it was already added", assemblyPath);
                        }
                        else
                        {
                            _moduleAssemblies.Add(assembly);
                            LoadReferencedAssemblies(assembly.GetReferencedAssemblies());
                        }
                    }
                }
                catch (Exception ex)
                {
                    Trace.Verbose("{0} exception while loading assembly file {1}: {2}", ex.GetType().Name, assemblyPath, ex.Message);
                }
            }
        }
 /// <summary>
 /// Gets matching files based on globbing patterns and/or absolute paths. If any absolute paths
 /// are provided, only those that actually exist are returned.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="directory">The directory to search.</param>
 /// <param name="patterns">The globbing patterns and/or absolute paths.</param>
 /// <returns>
 /// All files in the specified directory that match the globbing patterns and/or absolute paths.
 /// </returns>
 public static IEnumerable <IFile> GetFiles(this IReadOnlyFileSystem fileSystem, IDirectory directory, params string[] patterns)
 {
     _ = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     return(fileSystem.GetFiles(directory, (IEnumerable <string>)patterns));
 }
 /// <summary>
 /// Gets matching input files based on globbing patterns and/or absolute paths. If any absolute paths
 /// are provided, only those that actually exist are returned.
 /// </summary>
 /// <param name="fileSystem">The file system.</param>
 /// <param name="patterns">The globbing patterns and/or absolute paths.</param>
 /// <returns>All input files that match the globbing patterns and/or absolute paths.</returns>
 public static IEnumerable <IFile> GetInputFiles(this IReadOnlyFileSystem fileSystem, IEnumerable <string> patterns)
 {
     _ = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
     return(fileSystem.GetFiles(fileSystem.GetInputDirectory(), patterns));
 }
 public IEnumerable <FileName> GetFiles(DirectoryName directory, string searchPattern, DirectorySearchOptions searchOptions)
 {
     return(fileSystem.GetFiles(basePath.Combine(directory), searchPattern, searchOptions)
            .Select(file => basePath.GetRelativePath(file)));
 }