static string GetVersionFromFilepath(PortableExecutableWrapper executable) { // This is a hack! Sorry future me :( // The path to the DLL of a NuGet package always ends with /lib/<target framework>/<package-id>.dll, so // if we split on directory separators and take the 4th last segment that should always be the // version... assuming the NuGet package structure remains stable. var segments = executable.Filepath.Split(Path.DirectorySeparatorChar, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); var version = segments[^ 4];
internal PackageWithExecutableLoaded(PackageReferenceType type, string version, string name, PortableExecutableWrapper executable) { _executable = executable; ID = Guid.NewGuid(); ReferenceType = type; Name = name; Version = version; Parents = null; Children = null; }
public IPackageWithExecutableLoaded CreatePackage(PortableExecutableWrapper executable) { var name = executable.Name; var version = GetVersionFromFilepath(executable); if (!_cache.TryGetFirst(version, name, out var package)) { return(new PackageWithExecutableLoaded(PackageReferenceType.Unknown, version.ToString(), executable.Name, executable)); } return(new NuGetPackageWithExecutableLoaded(package, executable));
internal NuGetPackageWithExecutableLoaded(NuGetPackage package, PortableExecutableWrapper executable) { _package = package; _executable = executable; }