Skip to content

Commit

Permalink
patch(lib): support packages with different internal dll names than t…
Browse files Browse the repository at this point in the history
…he nuspec.
  • Loading branch information
randymarsh77 committed May 29, 2020
1 parent 13a85f7 commit aea7288
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tools/NuGetPackageInfo/NuGetPackageInfo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,24 @@ static void Main(string[] args)
?? throw new FormatException("No lib directory");

var targets = Directory.EnumerateDirectories(lib)
.Select(x =>
.Select(framework =>
{
var dlls = Directory.EnumerateFiles(framework)
.Where(x => x.EndsWith(".dll"))
.Select(GetLastPathComponent)
.ToList();
var dll = dlls.Count == 1
? dlls.First()
: (dlls.FirstOrDefault(x => x == $"{nuspec}.dll")
?? throw new FormatException("Unable to determine main dll"));
return (framework, dll);
}).Select(x =>
{
var (framework, dll) = x;
return new InfoDto.Target
{
Framework = x.Reverse().Substring(0, x.Reverse().IndexOf(Path.DirectorySeparatorChar)).Reverse(),
AssemblyVersion = ReadAssemblyVersion(Path.Combine(x, $"{nuspec}.dll")),
Framework = GetLastPathComponent(framework),
AssemblyVersion = ReadAssemblyVersion(Path.Combine(framework, dll)),
};
}).ToList();

Expand All @@ -68,6 +80,9 @@ private static string ReadAssemblyVersion(string dllPath)
return info.FileVersion;
}

private static string GetLastPathComponent(string path) =>
path.Reverse().Substring(0, path.Reverse().IndexOf(Path.DirectorySeparatorChar)).Reverse();

private sealed class InfoDto
{
public IReadOnlyList<Target> Targets { get; set; }
Expand Down

0 comments on commit aea7288

Please sign in to comment.