/// <summary> /// Loads the <see cref="Assembly"/> at the given path without locking the file. /// </summary> public static Assembly Load(string fullPath) { CompilerPathUtilities.RequireAbsolutePath(fullPath, "fullPath"); try { fullPath = Path.GetFullPath(fullPath); } catch (Exception e) { throw new ArgumentException(e.Message, "fullPath"); } lock (s_guard) { Assembly assembly; if (s_assembliesFromFiles.TryGetValue(fullPath, out assembly)) { return(assembly); } assembly = LoadCore(fullPath); if (!s_hookedAssemblyResolve) { s_hookedAssemblyResolve = true; AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; } return(assembly); } }
public FileTextLoader(string path, Encoding?defaultEncoding) { CompilerPathUtilities.RequireAbsolutePath(path, "path"); Path = path; DefaultEncoding = defaultEncoding; }
/// <summary> /// Creates an AnalyzerFileReference with the given <paramref name="fullPath"/> and <paramref name="assemblyLoader"/>. /// </summary> /// <param name="fullPath">Full path of the analyzer assembly.</param> /// <param name="assemblyLoader">Loader for obtaining the <see cref="Assembly"/> from the <paramref name="fullPath"/></param> public AnalyzerFileReference(string fullPath, IAnalyzerAssemblyLoader assemblyLoader) { CompilerPathUtilities.RequireAbsolutePath(fullPath, nameof(fullPath)); FullPath = fullPath; _assemblyLoader = assemblyLoader ?? throw new ArgumentNullException(nameof(assemblyLoader)); _diagnosticAnalyzers = new( this, typeof(DiagnosticAnalyzerAttribute), GetDiagnosticsAnalyzerSupportedLanguages, allowNetFramework : true ); _generators = new( this, typeof(GeneratorAttribute), GetGeneratorSupportedLanguages, allowNetFramework : false ); // Note this analyzer full path as a dependency location, so that the analyzer loader // can correctly load analyzer dependencies. assemblyLoader.AddDependencyLocation(fullPath); }
/// <summary> /// Creates metadata module from a file containing a portable executable image. /// </summary> /// <param name="fullPath">Absolute file path.</param> /// <remarks> /// The file might remain mapped (and read-locked) until this object is disposed. /// The memory map is only created for large files. Small files are read into memory. /// </remarks> /// <exception cref="ArgumentNullException"><paramref name="fullPath"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="fullPath"/> is not a valid absolute path.</exception> /// <exception cref="BadImageFormatException">The PE image format is invalid.</exception> /// <exception cref="IOException">Error reading file <paramref name="fullPath"/>. See <see cref="Exception.InnerException"/> for details.</exception> /// <exception cref="FileNotFoundException">File <paramref name="fullPath"/> not found.</exception> public static ModuleMetadata CreateFromFile(string fullPath) { CompilerPathUtilities.RequireAbsolutePath(fullPath, "fullPath"); FileStream fileStream; try { // Use FileShare.Delete to support files that are opened with DeleteOnClose option. fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete); } catch (ArgumentException e) { throw new ArgumentException(e.Message, "fullPath"); } catch (DirectoryNotFoundException e) { throw new FileNotFoundException(e.Message, fullPath, e); } catch (IOException) { throw; } catch (Exception e) { throw new IOException(e.Message, e); } return(CreateFromImageStream(fileStream)); }
public CompilationOutputFilesWithImplicitPdbPath(string assemblyFilePath = null) { if (assemblyFilePath != null) { CompilerPathUtilities.RequireAbsolutePath(assemblyFilePath, nameof(assemblyFilePath)); } AssemblyFilePath = assemblyFilePath; }
public AnalyzerFileReference(string fullPath, IAnalyzerAssemblyLoader assemblyLoader) { CompilerPathUtilities.RequireAbsolutePath(fullPath, nameof(fullPath)); FullPath = fullPath; _assemblyLoader = assemblyLoader ?? throw new ArgumentNullException(nameof(assemblyLoader)); _diagnosticAnalyzers = new Extensions <DiagnosticAnalyzer>(this, IsDiagnosticAnalyzerAttribute, GetDiagnosticsAnalyzerSupportedLanguages); _generators = new Extensions <ISourceGenerator>(this, IsGeneratorAttribute, GetGeneratorsSupportedLanguages); // Note this analyzer full path as a dependency location, so that the analyzer loader // can correctly load analyzer dependencies. assemblyLoader.AddDependencyLocation(fullPath); }
/// <exception cref="ArgumentNullException"><paramref name="fullPath"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="fullPath"/> is not a valid absolute path.</exception> /// <exception cref="IOException">Error reading file <paramref name="fullPath"/>. See <see cref="Exception.InnerException"/> for details.</exception> internal virtual Stream OpenRead(string fullPath) { CompilerPathUtilities.RequireAbsolutePath(fullPath, "fullPath"); try { // Use FileShare.Delete to support files that are opened with DeleteOnClose option. return(new FileStream(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)); } catch (Exception e) if (!(e is IOException)) { throw new IOException(e.Message, e); } }
protected PortableExecutableReference( MetadataReferenceProperties properties, string fullPath = null, DocumentationProvider initialDocumentation = null) : base(properties) { if (fullPath != null) { CompilerPathUtilities.RequireAbsolutePath(fullPath, "fullPath"); this.fullPath = FileUtilities.NormalizeAbsolutePath(fullPath); } this.lazyDocumentation = initialDocumentation; }
public ScriptMetadataResolver WithBaseDirectory(string baseDirectory) { if (BaseDirectory == baseDirectory) { return(this); } if (baseDirectory != null) { CompilerPathUtilities.RequireAbsolutePath(baseDirectory, nameof(baseDirectory)); } return(new ScriptMetadataResolver(SearchPaths, baseDirectory)); }
public ScriptMetadataResolver WithBaseDirectory(string?baseDirectory) { if (BaseDirectory == baseDirectory) { return(this); } if (baseDirectory != null) { CompilerPathUtilities.RequireAbsolutePath(baseDirectory, nameof(baseDirectory)); } return(new ScriptMetadataResolver(_resolver.WithRelativePathResolver( _resolver.PathResolver.WithBaseDirectory(baseDirectory)))); }
public CompilationOutputFiles(string assemblyFilePath = null, string pdbFilePath = null) { if (assemblyFilePath != null) { CompilerPathUtilities.RequireAbsolutePath(assemblyFilePath, nameof(assemblyFilePath)); } if (pdbFilePath != null) { CompilerPathUtilities.RequireAbsolutePath(pdbFilePath, nameof(pdbFilePath)); } AssemblyFilePath = assemblyFilePath; PdbFilePath = pdbFilePath; }
public void AddDependencyLocation(string fullPath) { CompilerPathUtilities.RequireAbsolutePath(fullPath, nameof(fullPath)); string simpleName = PathUtilities.GetFileName(fullPath, includeExtension: false); lock (_guard) { if (!_knownAssemblyPathsBySimpleName.TryGetValue(simpleName, out var paths)) { paths = new HashSet <string>(PathUtilities.Comparer); _knownAssemblyPathsBySimpleName.Add(simpleName, paths); } paths.Add(fullPath); } }
public void AddDependencyLocation(string fullPath) { CompilerPathUtilities.RequireAbsolutePath(fullPath, nameof(fullPath)); string simpleName = PathUtilities.GetFileName(fullPath, includeExtension: false); lock (_guard) { if (!_knownAssemblyPathsBySimpleName.TryGetValue(simpleName, out var paths)) { _knownAssemblyPathsBySimpleName.Add(simpleName, new List <string>() { fullPath }); } else if (!paths.Contains(fullPath)) { paths.Add(fullPath); } } }
public AnalyzerFileReference(string fullPath) { if (fullPath == null) { throw new ArgumentNullException("fullPath"); } // TODO: remove full path normalization CompilerPathUtilities.RequireAbsolutePath(fullPath, "fullPath"); try { this.fullPath = Path.GetFullPath(fullPath); } catch (Exception e) { throw new ArgumentException(e.Message, "fullPath"); } lazyAnalyzers = null; }
protected PortableExecutableReference( MetadataReferenceProperties properties, string fullPath = null, DocumentationProvider initialDocumentation = null) : base(properties) { // TODO: remove full path normalization if (fullPath != null) { CompilerPathUtilities.RequireAbsolutePath(fullPath, "fullPath"); try { this.fullPath = Path.GetFullPath(fullPath); } catch (Exception e) { throw new ArgumentException(e.Message, "fullPath"); } } this.lazyDocumentation = initialDocumentation; }
/// <summary> /// Creates an AnalyzerFileReference with the given <paramref name="fullPath"/>. /// </summary> /// <param name="fullPath">Full path of the analyzer assembly.</param> /// <param name="getAssembly">An optional assembly loader to override the default assembly load mechanism.</param> public AnalyzerFileReference(string fullPath, Func <string, Assembly> getAssembly = null) { if (fullPath == null) { throw new ArgumentNullException("fullPath"); } // TODO: remove full path normalization CompilerPathUtilities.RequireAbsolutePath(fullPath, "fullPath"); try { _fullPath = Path.GetFullPath(fullPath); } catch (Exception e) { throw new ArgumentException(e.Message, "fullPath"); } _lazyAllAnalyzers = default(ImmutableArray <DiagnosticAnalyzer>); _lazyAnalyzersPerLanguage = ImmutableDictionary <string, ImmutableArray <DiagnosticAnalyzer> > .Empty; _getAssembly = getAssembly; }
public override Stream OpenRead(string resolvedPath) { CompilerPathUtilities.RequireAbsolutePath(resolvedPath, nameof(resolvedPath)); return(FileUtilities.OpenRead(resolvedPath)); }
public Assembly LoadFromPath(string fullPath) { CompilerPathUtilities.RequireAbsolutePath(fullPath, nameof(fullPath)); return(LoadFromPathUnchecked(fullPath)); }
/// <summary> /// Finds all modules of an assembly on a specified path and builds an instance of <see cref="AssemblyMetadata"/> that represents them. /// </summary> /// <param name="fullPath">The full path to the assembly on disk.</param> /// <exception cref="ArgumentNullException"><paramref name="fullPath"/> is null.</exception> /// <exception cref="ArgumentException"><paramref name="fullPath"/> is not an absolute path.</exception> /// <exception cref="IOException">Error reading file <paramref name="fullPath"/>. See <see cref="Exception.InnerException"/> for details.</exception> public static AssemblyMetadata CreateFromFile(string fullPath) { CompilerPathUtilities.RequireAbsolutePath(fullPath, "fullPath"); return(new AssemblyMetadata(CreateModulesFromFile(fullPath))); }