public bool TryResolveAssemblyPaths(CompilationLibrary library, List <string>?assemblies) { ThrowHelper.ThrowIfNull(library); if (_nugetPackageDirectories == null || _nugetPackageDirectories.Length == 0 || !string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase)) { return(false); } foreach (string directory in _nugetPackageDirectories) { string packagePath; if (ResolverUtils.TryResolvePackagePath(_fileSystem, library, directory, out packagePath)) { if (TryResolveFromPackagePath(_fileSystem, library, packagePath, out IEnumerable <string>?fullPathsFromPackage)) { assemblies?.AddRange(fullPathsFromPackage); return(true); } } } return(false); }
public bool TryResolveAssemblyPaths(CompilationLibrary library, List <string> assemblies) { if (!string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase)) { return(false); } if (!string.IsNullOrEmpty(_packageCacheDirectory)) { var hashSplitterPos = library.Hash.IndexOf('-'); if (hashSplitterPos <= 0 || hashSplitterPos == library.Hash.Length - 1) { throw new InvalidOperationException($"Invalid hash entry '{library.Hash}' for package '{library.Name}'"); } string packagePath; if (ResolverUtils.TryResolvePackagePath(library, _packageCacheDirectory, out packagePath)) { var hashAlgorithm = library.Hash.Substring(0, hashSplitterPos); var cacheHashPath = Path.Combine(packagePath, $"{library.Name}.{library.Version}.nupkg.{hashAlgorithm}"); if (File.Exists(cacheHashPath) && File.ReadAllText(cacheHashPath) == library.Hash.Substring(hashSplitterPos + 1)) { assemblies.AddRange(ResolverUtils.ResolveFromPackagePath(library, packagePath)); return(true); } } } return(false); }
public bool TryResolveAssemblyPaths(CompilationLibrary library, List <string> assemblies) { var isProject = string.Equals(library.Type, "project", StringComparison.OrdinalIgnoreCase); if (!isProject && !string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase) && !string.Equals(library.Type, "referenceassembly", StringComparison.OrdinalIgnoreCase)) { return(false); } var refsPath = Path.Combine(_basePath, "refs"); var hasRefs = _fileSystem.Directory.Exists(refsPath); // Resolving packages and reference assebmlies requires refs folder to exist if (!isProject && !hasRefs) { return(false); } var directories = new List <string>() { _basePath }; if (hasRefs) { directories.Insert(0, refsPath); } foreach (var assembly in library.Assemblies) { bool resolved = false; var assemblyFile = Path.GetFileName(assembly); foreach (var directory in directories) { string fullName; if (ResolverUtils.TryResolveAssemblyFile(_fileSystem, directory, assemblyFile, out fullName)) { assemblies.Add(fullName); resolved = true; break; } } if (!resolved) { throw new InvalidOperationException( $"Can not find assembly file {assemblyFile} at '{string.Join(",", directories)}'"); } } return(true); }
public bool TryResolveAssemblyPaths(CompilationLibrary library, List <string> assemblies) { if (string.IsNullOrEmpty(_nugetPackageDirectory) || !string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase)) { return(false); } string packagePath; if (ResolverUtils.TryResolvePackagePath(_fileSystem, library, _nugetPackageDirectory, out packagePath)) { assemblies.AddRange(ResolverUtils.ResolveFromPackagePath(_fileSystem, library, packagePath)); return(true); } return(false); }
public bool TryResolveAssemblyPaths(CompilationLibrary library, List <string> assemblies) { if (_nugetPackageDirectories == null || _nugetPackageDirectories.Length == 0 || !string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase)) { return(false); } foreach (var directory in _nugetPackageDirectories) { string packagePath; if (ResolverUtils.TryResolvePackagePath(_fileSystem, library, directory, out packagePath)) { assemblies.AddRange(ResolverUtils.ResolveFromPackagePath(_fileSystem, library, packagePath)); return(true); } } return(false); }
private static bool TryResolveFromPackagePath(IFileSystem fileSystem, CompilationLibrary library, string basePath, [MaybeNullWhen(false)] out IEnumerable <string> results) { var paths = new List <string>(); foreach (string assembly in library.Assemblies) { if (!ResolverUtils.TryResolveAssemblyFile(fileSystem, basePath, assembly, out string fullName)) { // if one of the files can't be found, skip this package path completely. // there are package paths that don't include all of the "ref" assemblies // (ex. ones created by 'dotnet store') results = null; return(false); } paths.Add(fullName); } results = paths; return(true); }
public bool TryResolveAssemblyPaths(CompilationLibrary library, List <string> assemblies) { var isProject = string.Equals(library.Type, "project", StringComparison.OrdinalIgnoreCase); var isPackage = string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase); if (!isProject && !isPackage && !string.Equals(library.Type, "referenceassembly", StringComparison.OrdinalIgnoreCase)) { return(false); } var refsPath = Path.Combine(_basePath, RefsDirectoryName); var isPublished = _fileSystem.Directory.Exists(refsPath); // Resolving reference assebmlies requires refs folder to exist if (!isProject && !isPackage && !isPublished) { return(false); } var directories = new List <string>() { _basePath }; if (isPublished) { directories.Insert(0, refsPath); } // Only packages can come from shared runtime var sharedPath = _dependencyContextPaths.SharedRuntime; if (isPublished && isPackage && !string.IsNullOrEmpty(sharedPath)) { var sharedDirectory = Path.GetDirectoryName(sharedPath); var sharedRefs = Path.Combine(sharedDirectory, RefsDirectoryName); if (_fileSystem.Directory.Exists(sharedRefs)) { directories.Add(sharedRefs); } directories.Add(sharedDirectory); } foreach (var assembly in library.Assemblies) { bool resolved = false; var assemblyFile = Path.GetFileName(assembly); foreach (var directory in directories) { string fullName; if (ResolverUtils.TryResolveAssemblyFile(_fileSystem, directory, assemblyFile, out fullName)) { assemblies.Add(fullName); resolved = true; break; } } if (!resolved) { // throw in case when we are published app and nothing found // because we cannot rely on nuget package cache in this case if (isPublished) { throw new InvalidOperationException( $"Can not find assembly file {assemblyFile} at '{string.Join(",", directories)}'"); } return(false); } } return(true); }
public bool TryResolveAssemblyPaths(CompilationLibrary library, List <string> assemblies) { var isProject = string.Equals(library.Type, "project", StringComparison.OrdinalIgnoreCase) || string.Equals(library.Type, "msbuildproject", StringComparison.OrdinalIgnoreCase); var isPackage = string.Equals(library.Type, "package", StringComparison.OrdinalIgnoreCase); var isReferenceAssembly = string.Equals(library.Type, "referenceassembly", StringComparison.OrdinalIgnoreCase); if (!isProject && !isPackage && !isReferenceAssembly && !string.Equals(library.Type, "reference", StringComparison.OrdinalIgnoreCase)) { return(false); } var refsPath = Path.Combine(_basePath, RefsDirectoryName); var isPublished = _fileSystem.Directory.Exists(refsPath); string RunTimeDirectoryName = "runtime"; var runTimeRefsPath = Path.Combine(_basePath, RunTimeDirectoryName, RefsDirectoryName); var isRunPublished = _fileSystem.Directory.Exists(runTimeRefsPath); // Resolving reference assemblies requires refs folder to exist if (isReferenceAssembly && !isPublished && !isRunPublished) { return(false); } var directories = new List <string>() { _basePath }; var runTimePath = Path.Combine(_basePath, RunTimeDirectoryName); var isRunTime = _fileSystem.Directory.Exists(runTimePath); if (isRunTime) { directories.Insert(0, runTimePath); } if (isPublished) { directories.Insert(0, refsPath); } if (isRunPublished) { directories.Insert(0, runTimeRefsPath); } // Only packages can come from shared runtime var sharedPath = _dependencyContextPaths.SharedRuntime; if (isPublished && isPackage && !string.IsNullOrEmpty(sharedPath)) { var sharedDirectory = Path.GetDirectoryName(sharedPath); var sharedRefs = Path.Combine(sharedDirectory, RefsDirectoryName); if (_fileSystem.Directory.Exists(sharedRefs)) { directories.Add(sharedRefs); } directories.Add(sharedDirectory); } var paths = new List <string>(); foreach (var assembly in library.Assemblies) { bool resolved = false; var assemblyFile = Path.GetFileName(assembly); foreach (var directory in directories) { string fullName; if (ResolverUtils.TryResolveAssemblyFile(_fileSystem, directory, assemblyFile, out fullName)) { paths.Add(fullName); resolved = true; break; } } if (!resolved) { return(false); } } // only modify the assemblies parameter if we've resolved all files assemblies?.AddRange(paths); return(true); }