diff --git a/AGENTS.md b/AGENTS.md index 0b7b699..5cbfdee 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,8 +1,8 @@ # assembly-differ A .NET tool that diffs the public API of two sets of assemblies and suggests the version change it needs (none, -patch, minor, major). Each side comes from a provider: `assembly`, `directory`, `nuget`, `previous-nuget` or -`github`; the result is written as `xml`, `markdown`, `asciidoc` or `github-comment`. It is also published as a +patch, minor, major). A command per source (`release`, `files`, `nuget`, `github`) picks the two sides; the result is +written as `markdown`, `xml`, `asciidoc`, `github-comment` or `json`. It is also published as a distroless container (`ghcr.io/nullean/assembly-differ`) and a GitHub Action (`action.yml`) that runs it. ## Layout @@ -80,8 +80,10 @@ one release label. - `Engine/` reproduces the reports of JustAssembly, which it replaced, quirks included: a type that became less visible is reported as more visible, and nested types are named `.Name`. Changing a report is a change to the CLI contract. -- The CLI surface (`diff`, the provider specs and the flags) is the contract `action.yml`, the container and other - repositories' builds rely on. Removing or renaming any of it is a breaking change. +- The CLI surface is the contract `action.yml`, the container and other repositories' builds rely on: the commands + (`release`, `files`, `nuget`, `github`) and their options, and the hidden `diff` with its provider specs and flags. + Removing or renaming any of it is a breaking change. `ApiCommands.cs` holds the commands, `DiffRunner.cs` the + comparison they share with `diff`. - The build diffs this tool against its own previous release (`generateapichanges`), so a broken diff fails its own CI. - Build targets are Make.Fs `target { }` blocks in `build/scripts/Program.fs` whose commands are Proc.Fs `sh $"…"` lines; values come from `text` inside `shell { }` (`Versions.fs`). Do not call the C# `ProcNet` API from the build. diff --git a/README.md b/README.md index e27f6c6..b540725 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Proc 0.14.0 added a `CancellationToken` to its `Start*` methods. Diffing it agai each old overload deleted and its replacement added, which makes the release a major change: ```console -$ assembly-differ diff "nuget|Proc|0.13.0|netstandard2.0" "nuget|Proc|0.14.0|netstandard2.0" -t proc +$ assembly-differ nuget Proc 0.13.0 0.14.0 -t proc -f xml [diff] Difference found: NuGetAssemblyProvider:proc.dll and NuGetAssemblyProvider:proc.dll @@ -61,51 +61,63 @@ runtime installed. ## Quick start -Diff the last release on nuget.org against what you just built, as Markdown, and fail the build on a breaking change: +Compare the package you just packed with its last release on nuget.org, and fail the build on a breaking change: ```sh -assembly-differ diff "previous-nuget|MyLib|1.3.0|net8.0" "directory|src/MyLib/bin/Release/net8.0" -t MyLib -f markdown -p major +assembly-differ release build/output/MyLib.1.3.0.nupkg --fail-on major ``` -`previous-nuget` finds the latest release before `1.3.0`, so the same command keeps working as you release. +The package id and version come from the `.nupkg`, and the release compared with is the newest one before `1.3.0`, so +the same command keeps working as you release. -Each side is a provider spec, and the two sides can mix: - -| Spec | Assemblies | +| Command | Compares | |---|---| -| `assembly\|` | one dll | -| `directory\|` | every dll in a directory, matched by file name against the other side | -| `nuget\|\|\|[tfm]` | a package from the NuGet sources your NuGet.config lists | -| `previous-nuget\|\|\|[tfm]` | the release on nuget.org before `` | -| `github\|\|\|\|` | a commit, cloned and built with the command you give | +| `release ` | a new build, as a `.nupkg`, a `.dll` or a directory, with the release before it on nuget.org; pass `--package` and `--version` unless `` is a `.nupkg` | +| `files ` | two local builds, each a `.dll`, a directory of dlls or a `.nupkg` | +| `nuget ` | two published versions, from the NuGet sources your NuGet.config lists | +| `github --build --artifacts ` | a new build with an older commit, cloned and built with the command you give | + +Every command takes the same options: -| Flag | What | +| Option | What | |---|---| -| `-t`, `--target` | only diff these assemblies (repeatable); defaults to every assembly both sides have | -| `-f`, `--format` | `xml` (default), `markdown`, `asciidoc`, `github-comment` (a pull request comment with a collapsible diff per assembly) or `json` (`api-changes.json`: the suggested change, breaking changes and every change as a tree, for tools) | -| `-o`, `--output` | output directory or file; without it the diff only goes to the console | -| `-p`, `--prevent-change` | exit with `4` when the suggested change is at least `patch`, `minor` or `major`; `none` (the default) never fails | -| `-a`, `--allow-empty-previous-nuget` | succeed when `previous-nuget` finds no earlier release, for a first release | +| `-t`, `--target` | only compare these assemblies, by file name without extension (repeatable); defaults to every assembly both sides have | +| `-f`, `--format` | `markdown` (default), `xml`, `asciidoc`, `github-comment` (a pull request comment with a collapsible diff per assembly) or `json` (`api-changes.json`: the suggested change, breaking changes and every change as a tree, for tools) | +| `-o`, `--output` | a directory or file to write the report to, besides the console | +| `--fail-on` | exit with `4` when the suggested change is at least `patch`, `minor` or `major`; `none` (the default) never fails | +| `--framework` | the target framework to compare, such as `net8.0` (`files`, `nuget` and `release`); defaults to the newest the packages share | + +A single assembly on each side is compared whatever its file name. With more, assemblies pair by file name, and one +only a side has is printed; it counts as removed or added API when `--target` names it. The suggested change follows semantic versioning. It is `None` when the public API is unchanged, `Patch` when only -assembly references changed, and `Minor` when API was only added or attributes changed: diffing Proc 0.12.0 against -0.13.0, which only adds `NoWrapInThread`, suggests `Minor`. It is `Major` when something was removed or changed, and -when a new interface member, abstract member or `required` member makes existing code change. Always name the `diff` subcommand: a provider spec as the first argument is read as -a command name. +assembly references changed, and `Minor` when API was only added or attributes changed: Proc 0.13.0 marks +`NoWrapInThread` `[Obsolete]`, and `assembly-differ nuget Proc 0.12.0 0.13.0` suggests `Minor`. It is `Major` when +something was removed or changed, and when a new interface member, abstract member or `required` member makes existing +code change. More examples: ```sh # two local builds, every dll matched by name -assembly-differ diff "directory|build/1.2.0" "directory|build/1.3.0" +assembly-differ files build/1.2.0 build/1.3.0 -# two published packages -assembly-differ diff "nuget|Proc|0.13.0|netstandard2.0" "nuget|Proc|0.14.0|netstandard2.0" -t proc -f markdown +# two published packages, as Markdown +assembly-differ nuget Proc 0.13.0 0.14.0 -t proc -# the last release before 0.14.0 against a local build -assembly-differ diff "previous-nuget|Proc|0.14.0|netstandard2.0" "directory|build/proc" -t proc +# the release before 1.3.0 against a build directory +assembly-differ release src/MyLib/bin/Release/net8.0 --package MyLib --version 1.3.0 -t MyLib ``` +### Provider specs + +Before it had a command per source, the tool took two provider specs, and `diff` still does, unchanged, for the builds +that call it: `assembly-differ diff "previous-nuget|MyLib|1.3.0|net8.0" "directory|bin" -t MyLib -p major`. A spec is +`assembly|`, `directory|`, `nuget|||[tfm]`, `previous-nuget|||[tfm]` or +`github||||`. Its options are `-t`, `-o`, `-f` (default +`xml`), `-p`/`--prevent-change` in place of `--fail-on`, and `-a`/`--allow-empty-previous-nuget`, which succeeds when +`previous-nuget` finds no earlier release. + ### GitHub Action ```yaml @@ -125,7 +137,7 @@ Container actions run on Linux runners only. The same image works anywhere `docker run` does, such as GitLab CI or a machine without the .NET SDK: ```sh -docker run --rm -v "$(pwd)":/workspace ghcr.io/nullean/assembly-differ:edge diff "directory|/workspace/old" "directory|/workspace/new" +docker run --rm -v "$(pwd)":/workspace ghcr.io/nullean/assembly-differ:edge files /workspace/old /workspace/new ``` It is native-AOT on a chiseled `runtime-deps` base, with no shell, running as a non-root user. `edge` tracks the latest diff --git a/build/scripts/Program.fs b/build/scripts/Program.fs index 5c1b6c0..330f2ef 100644 --- a/build/scripts/Program.fs +++ b/build/scripts/Program.fs @@ -133,6 +133,11 @@ let main argv = let! result = text $"{binary} diff 'previous-nuget|Proc|0.18.0' 'nuget|Proc|0.20.0' --target Proc -f markdown" printfn "%s" result for expected in [ "Found previous nuget package found for Proc 0.18.0: 0.17.0"; "Suggested version change: Minor" ] do - if not (result.Contains expected) then failwithf "the native-AOT binary did not print '%s'" expected } + if not (result.Contains expected) then failwithf "the native-AOT binary did not print '%s'" expected + // the commands bind through argh's generated code; Proc 0.13.0 only marks NoWrapInThread obsolete + let! command = text $"{binary} nuget Proc 0.12.0 0.13.0 --target Proc --format json" + printfn "%s" command + if not (command.Contains "\"suggestedVersionChange\": \"Minor\"") then + failwith "the native-AOT binary's nuget command did not suggest Minor" } app.RunAsync(argv).GetAwaiter().GetResult() diff --git a/src/assembly-differ/ApiCommands.cs b/src/assembly-differ/ApiCommands.cs new file mode 100644 index 0000000..de3392c --- /dev/null +++ b/src/assembly-differ/ApiCommands.cs @@ -0,0 +1,194 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; +using System.Linq; +using Differ.Engine; +using Differ.Providers; +using Differ.Providers.GitHub; +using Differ.Providers.NuGet; +using Differ.Providers.PreviousNuGet; +using NuGet.Frameworks; +using Nullean.Argh; + +namespace Differ; + +/// How a comparison is reported, and when it fails. +public sealed class ReportOptions +{ + /// -t, --target, Only compare these assemblies, by file name without extension. Repeat it for more than one. + public List? Target { get; set; } + + /// -f, --format, The report: markdown, xml, asciidoc, github-comment or json. + [AllowedValues("markdown", "xml", "asciidoc", "github-comment", "json")] + public string Format { get; set; } = "markdown"; + + /// -o, --output, A directory or file to write the report to, besides the console. + public string? Output { get; set; } + + /// Exit with code 4 when the suggested version change is at least this: none (never), patch, minor or major. + [AllowedValues("none", "patch", "minor", "major")] + public string FailOn { get; set; } = "none"; +} + +/// Compares the public API of two versions of a library and suggests the version change it calls for. +internal sealed class ApiCommands +{ + /// Compares two local builds: dlls, directories of dlls, or .nupkg files. + /// The old build: a .dll, a directory or a .nupkg. + /// The new build: a .dll, a directory or a .nupkg. + /// The target framework to take from a .nupkg, such as net8.0. Defaults to the newest both packages ship. + /// How to report the comparison. + /// assembly-differ files bin/1.2.0/MyLib.dll bin/1.3.0/MyLib.dll + /// assembly-differ files MyLib.1.2.0.nupkg MyLib.1.3.0.nupkg --framework net8.0 + [CommandName("files")] + public int Files([Argument] string old, [Argument] string @new, string? framework = null, [AsParameters] ReportOptions? report = null) => + Run( + () => + { + var chosen = Framework(framework, old, @new); + return (Local(old, chosen), Local(@new, chosen)); + }, + report + ); + + /// Compares two published versions of a package. + /// The package id. + /// The old version. + /// The new version. + /// The target framework to compare, such as net8.0. Defaults to the first the package ships. + /// How to report the comparison. + /// assembly-differ nuget Proc 0.13.0 0.14.0 + [CommandName("nuget")] + public int NuGet( + [Argument] string package, + [Argument] string oldVersion, + [Argument] string newVersion, + string? framework = null, + [AsParameters] ReportOptions? report = null + ) => + Run( + () => + { + var installer = new Providers.NuGet.NuGet(); + return (new DiffSide(new NuGetAssemblyProvider(installer, Spec(package, oldVersion, framework)), "nuget"), new DiffSide( + new NuGetAssemblyProvider(installer, Spec(package, newVersion, framework)), + "nuget" + )); + }, + report + ); + + /// Compares a new build with the release before it on nuget.org. + /// + /// Give a .nupkg and the package id and version come from it; for a .dll or a directory, pass --package and --version. + /// The release compared with is the newest one before that version. + /// + /// The new build: a .nupkg, a .dll or a directory. + /// The package id; read from a .nupkg when not given. + /// The version being released; read from a .nupkg when not given. + /// The target framework to compare, such as net8.0. Defaults to the newest the .nupkg ships. + /// How to report the comparison. + /// assembly-differ release build/output/MyLib.1.3.0.nupkg --fail-on major + /// assembly-differ release src/MyLib/bin/Release/net8.0 --package MyLib --version 1.3.0 -t MyLib + [CommandName("release")] + public int Release( + [Argument] string path, + string? package = null, + string? version = null, + string? framework = null, + [AsParameters] ReportOptions? report = null + ) => + Run( + () => + { + if (Nupkg.IsPackage(path)) + { + var identity = Nupkg.Identity(path); + package ??= identity.Id; + version ??= identity.Version; + } + if (package is null || version is null) + throw new ArgumentException("pass --package and --version, or a .nupkg to read them from"); + + var chosen = Framework(framework, path); + return (new DiffSide( + new NuGetAssemblyProvider(new PreviousNugetLocator(), Spec(package, version, chosen?.GetShortFolderName()), "previous-nuget"), + "previous-nuget" + ), Local(path, chosen)); + }, + report + ); + + /// Compares a new build with an older commit of a GitHub repository, built with the command you give. + /// The repository as owner/name. + /// The commit, branch or tag to build as the old version. + /// The new build: a .dll or a directory. + /// The command that builds the old commit, run in its checkout. + /// Where the build leaves the assemblies, relative to the checkout. + /// How to report the comparison. + /// assembly-differ github nullean/proc 0.13.0 src/Proc/bin/Release/netstandard2.0 --build "dotnet build -c Release" --artifacts src/Proc/bin/Release/netstandard2.0 + [CommandName("github")] + public int GitHub( + [Argument] string repository, + [Argument] string commit, + [Argument] string path, + string build, + string artifacts, + [AsParameters] ReportOptions? report = null + ) => + Run( + () => + (new DiffSide( + new GitHubAssemblyProviderFactory(new Git(Environment.GetEnvironmentVariable("GIT"))).Create([repository, commit, build, artifacts]), + "github" + ), Local(path, null)), + report + ); + + private static int Run(Func<(DiffSide Old, DiffSide New)> sides, ReportOptions? report) + { + report ??= new ReportOptions(); + var targets = new HashSet(report.Target ?? [], StringComparer.OrdinalIgnoreCase); + try + { + var (oldSide, newSide) = sides(); + var failOn = Enum.Parse(report.FailOn, ignoreCase: true); + return DiffRunner.Run(oldSide, newSide, new DiffSettings(targets, report.Format, report.Output, failOn, AllowEmptyPreviousNuget: false)); + } + catch (Exception e) when (e is ArgumentException or FileNotFoundException or DirectoryNotFoundException) + { + Console.Error.WriteLine($"[diff] {e.Message}"); + return 1; + } + catch (Exception e) + { + Console.Error.WriteLine(e); + return 1; + } + } + + private static string[] Spec(string package, string version, string? framework) => framework is null ? [package, version] : [package, version, framework]; + + /// A local build: a .nupkg, a directory of assemblies, or one assembly. + private static DiffSide Local(string path, NuGetFramework? framework) + { + if (Nupkg.IsPackage(path)) + return new DiffSide(new NupkgAssemblyProvider(path, framework ?? Nupkg.Frameworks(path).FirstOrDefault() ?? NuGetFramework.AnyFramework), "nupkg"); + if (Directory.Exists(path)) + return new DiffSide(new DirectoryAssemblyProvider(path), "directory"); + return new DiffSide(new AssemblyProvider(path), "assembly"); + } + + /// The framework to compare: the one given, or the newest every .nupkg among the paths ships. + private static NuGetFramework? Framework(string? framework, params string[] paths) + { + if (framework is not null) + return NuGetFramework.ParseFolder(framework); + var packages = paths.Where(Nupkg.IsPackage).Select(Nupkg.Frameworks).ToList(); + if (packages.Count == 0) + return null; + var common = packages.Skip(1).Aggregate((IEnumerable)packages[0], (shared, next) => shared.Where(next.Contains)).FirstOrDefault(); + return common ?? throw new ArgumentException("the packages ship no target framework in common; pass --framework"); + } +} diff --git a/src/assembly-differ/DiffCommand.cs b/src/assembly-differ/DiffCommand.cs index 9239030..1b9b39a 100644 --- a/src/assembly-differ/DiffCommand.cs +++ b/src/assembly-differ/DiffCommand.cs @@ -16,8 +16,8 @@ namespace Differ; internal sealed class DiffCommands { /// - /// Compares and diffs assemblies from different sources, outputting differences in XML, - /// Markdown, or AsciiDoc. + /// Compares the public API of two versions of a library and suggests the version change it calls for. Pick a command + /// for where the versions come from; diff with provider specs, such as nuget|Proc|0.13.0, still works for existing builds. /// /// /// Old assembly provider: assembly|<path>, directory|<path>, nuget|<id>|<version>|[tfm], @@ -39,6 +39,7 @@ internal sealed class DiffCommands /// [DefaultCommand] [CommandName("diff")] + [Hidden] public int Diff( [Argument] string first, [Argument] string second, @@ -61,15 +62,6 @@ public int Diff( new GitHubAssemblyProviderFactory(new Git(Environment.GetEnvironmentVariable("GIT"))) ); - var exporters = new ExporterCollection( - new XmlExporter(), - new MarkdownExporter(), - new AsciiDocExporter(), - new GitHubActionCommentExporter(), - new JsonExporter() - ); - - var outputWriterFactory = new OutputWriterFactory(output); var targets = new HashSet(StringComparer.OrdinalIgnoreCase); foreach (var t in target ?? []) foreach (var part in t.Split(',', '|')) @@ -82,95 +74,16 @@ public int Diff( var secondProvider = providers.GetProvider(second); var firstProviderName = providers.GetProviderName(first); var secondProviderName = providers.GetProviderName(second); - - if (!exporters.Contains(format)) - throw new Exception($"No exporter for format '{format}'"); - - var exporter = exporters[format]; - - var firstAssemblies = firstProvider.GetAssemblies(targets).ToList(); - var secondAssemblies = secondProvider.GetAssemblies(targets).ToList(); - var pairs = CreateAssemblyPairs(firstAssemblies, secondAssemblies).ToList(); - var onlyInFirst = Unpaired(firstAssemblies, pairs.Select(p => p.First)); - var onlyInSecond = Unpaired(secondAssemblies, pairs.Select(p => p.Second)); - - if (!pairs.Any()) - { - if (allowEmptyPreviousNuget && (firstProviderName == "previous-nuget" || secondProviderName == "previous-nuget")) - { - Console.WriteLine($"[diff] No previous nuget found for: {firstProviderName}"); - Console.WriteLine($"[diff] {firstProvider.GetType().Name}: {firstAssemblies.Count} assemblies"); - Console.WriteLine($"[diff] {secondProvider.GetType().Name}: {secondAssemblies.Count} assemblies"); - Console.WriteLine($"[diff]"); - Console.WriteLine($"[diff] NOT treated as an error because --allow-empty-previous-nuget was set"); - return 0; - } - - Console.Error.WriteLine($"[diff] Unable to create diff!"); - Console.Error.WriteLine($"[diff] {firstProvider.GetType().Name}: {firstAssemblies.Count} assemblies"); - Console.Error.WriteLine($"[diff] {secondProvider.GetType().Name}: {secondAssemblies.Count} assemblies"); - return 1; - } - - foreach (var assembly in onlyInFirst) - Console.WriteLine($"[diff] Only in the old version: {assembly.Name}"); - foreach (var assembly in onlyInSecond) - Console.WriteLine($"[diff] Only in the new version: {assembly.Name}"); - - // without targets, an assembly only one side has is as likely a dependency as API, so it only counts when named - var result = new AllComparisonResults(pairs, preventChangeValue) - { - Removed = targets.Count > 0 ? onlyInFirst : [], - Added = targets.Count > 0 ? onlyInSecond : [], - }; - foreach (var assemblyPair in pairs) - { - assemblyPair.Diff = ApiDiff.Compare(assemblyPair.First.FullName, assemblyPair.Second.FullName); - - if (assemblyPair.Diff == null) - { - Console.WriteLine($"[diff] No diff between {assemblyPair.First.FullName} and {assemblyPair.Second.FullName}"); - continue; - } - Console.WriteLine( - $"[diff] Difference found: {firstProvider.GetType().Name}:{assemblyPair.First.Name} and {secondProvider.GetType().Name}:{assemblyPair.Second.Name}" - ); - - if (exporter is IAssemblyComparisonExporter c) - c.Export(assemblyPair, outputWriterFactory); - } - if (exporter is IAllComparisonResultsExporter allExporter) - allExporter.Export(result, outputWriterFactory); - - if (preventChangeValue > SuggestedVersionChange.None && result.SuggestedVersionChange >= preventChangeValue) - { - Console.Error.WriteLine( - $"[diff] Needed version change '{result.SuggestedVersionChange}' exceeds or equals configured lock: '{preventChangeValue}" - ); - return 4; - } - Console.WriteLine($"[diff] Suggested version change: {result.SuggestedVersionChange}"); + return DiffRunner.Run( + new DiffSide(firstProvider, firstProviderName), + new DiffSide(secondProvider, secondProviderName), + new DiffSettings(targets, format, output, preventChangeValue, allowEmptyPreviousNuget) + ); } catch (Exception e) { Console.Error.WriteLine(e); return 1; } - return 0; - } - - /// - /// Pairs the assemblies by file name. When each side has exactly one assembly they are compared whatever their names, - /// such as a dll and a renamed copy of it. - /// - private static IEnumerable CreateAssemblyPairs(IReadOnlyList first, IReadOnlyList second) => - first.Count == 1 && second.Count == 1 - ? [new AssemblyComparison(first[0], second[0])] - : first.Join(second, f => f.Name.ToUpperInvariant(), f => f.Name.ToUpperInvariant(), (f1, f2) => new AssemblyComparison(f1, f2)); - - private static List Unpaired(IEnumerable assemblies, IEnumerable paired) - { - var pairedPaths = new HashSet(paired.Select(p => p.FullName)); - return assemblies.Where(a => !pairedPaths.Contains(a.FullName)).ToList(); } } diff --git a/src/assembly-differ/DiffRunner.cs b/src/assembly-differ/DiffRunner.cs new file mode 100644 index 0000000..90c7f17 --- /dev/null +++ b/src/assembly-differ/DiffRunner.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Differ.Engine; +using Differ.Exporters; +using Differ.Providers; + +namespace Differ; + +/// One side of a comparison: where its assemblies come from, and the provider's name. +internal sealed record DiffSide(IAssemblyProvider Provider, string ProviderName); + +internal sealed record DiffSettings(HashSet Targets, string Format, string? Output, SuggestedVersionChange FailOn, bool AllowEmptyPreviousNuget); + +/// Compares the assemblies two sides provide, writes the report and returns the exit code. +internal static class DiffRunner +{ + public static int Run(DiffSide first, DiffSide second, DiffSettings settings) + { + var exporters = new ExporterCollection( + new XmlExporter(), + new MarkdownExporter(), + new AsciiDocExporter(), + new GitHubActionCommentExporter(), + new JsonExporter() + ); + var outputWriterFactory = new OutputWriterFactory(settings.Output); + var targets = settings.Targets; + var format = settings.Format; + var preventChangeValue = settings.FailOn; + var allowEmptyPreviousNuget = settings.AllowEmptyPreviousNuget; + var firstProvider = first.Provider; + var secondProvider = second.Provider; + var firstProviderName = first.ProviderName; + var secondProviderName = second.ProviderName; + + try + { + if (!exporters.Contains(format)) + throw new Exception($"No exporter for format '{format}'"); + + var exporter = exporters[format]; + + var firstAssemblies = firstProvider.GetAssemblies(targets).ToList(); + var secondAssemblies = secondProvider.GetAssemblies(targets).ToList(); + var pairs = CreateAssemblyPairs(firstAssemblies, secondAssemblies).ToList(); + var onlyInFirst = Unpaired(firstAssemblies, pairs.Select(p => p.First)); + var onlyInSecond = Unpaired(secondAssemblies, pairs.Select(p => p.Second)); + + if (!pairs.Any()) + { + if (allowEmptyPreviousNuget && (firstProviderName == "previous-nuget" || secondProviderName == "previous-nuget")) + { + Console.WriteLine($"[diff] No previous nuget found for: {firstProviderName}"); + Console.WriteLine($"[diff] {firstProvider.GetType().Name}: {firstAssemblies.Count} assemblies"); + Console.WriteLine($"[diff] {secondProvider.GetType().Name}: {secondAssemblies.Count} assemblies"); + Console.WriteLine($"[diff]"); + Console.WriteLine($"[diff] NOT treated as an error because --allow-empty-previous-nuget was set"); + return 0; + } + + Console.Error.WriteLine($"[diff] Unable to create diff!"); + Console.Error.WriteLine($"[diff] {firstProvider.GetType().Name}: {firstAssemblies.Count} assemblies"); + Console.Error.WriteLine($"[diff] {secondProvider.GetType().Name}: {secondAssemblies.Count} assemblies"); + return 1; + } + + foreach (var assembly in onlyInFirst) + Console.WriteLine($"[diff] Only in the old version: {assembly.Name}"); + foreach (var assembly in onlyInSecond) + Console.WriteLine($"[diff] Only in the new version: {assembly.Name}"); + + // without targets, an assembly only one side has is as likely a dependency as API, so it only counts when named + var result = new AllComparisonResults(pairs, preventChangeValue) + { + Removed = targets.Count > 0 ? onlyInFirst : [], + Added = targets.Count > 0 ? onlyInSecond : [], + }; + foreach (var assemblyPair in pairs) + { + assemblyPair.Diff = ApiDiff.Compare(assemblyPair.First.FullName, assemblyPair.Second.FullName); + + if (assemblyPair.Diff == null) + { + Console.WriteLine($"[diff] No diff between {assemblyPair.First.FullName} and {assemblyPair.Second.FullName}"); + continue; + } + Console.WriteLine( + $"[diff] Difference found: {firstProvider.GetType().Name}:{assemblyPair.First.Name} and {secondProvider.GetType().Name}:{assemblyPair.Second.Name}" + ); + + if (exporter is IAssemblyComparisonExporter c) + c.Export(assemblyPair, outputWriterFactory); + } + if (exporter is IAllComparisonResultsExporter allExporter) + allExporter.Export(result, outputWriterFactory); + + if (preventChangeValue > SuggestedVersionChange.None && result.SuggestedVersionChange >= preventChangeValue) + { + Console.Error.WriteLine( + $"[diff] Needed version change '{result.SuggestedVersionChange}' exceeds or equals configured lock: '{preventChangeValue}" + ); + return 4; + } + Console.WriteLine($"[diff] Suggested version change: {result.SuggestedVersionChange}"); + } + catch (Exception e) + { + Console.Error.WriteLine(e); + return 1; + } + return 0; + } + + /// + /// Pairs the assemblies by file name. When each side has exactly one assembly they are compared whatever their names, + /// such as a dll and a renamed copy of it. + /// + private static IEnumerable CreateAssemblyPairs(IReadOnlyList first, IReadOnlyList second) => + first.Count == 1 && second.Count == 1 + ? [new AssemblyComparison(first[0], second[0])] + : first.Join(second, f => f.Name.ToUpperInvariant(), f => f.Name.ToUpperInvariant(), (f1, f2) => new AssemblyComparison(f1, f2)); + + private static List Unpaired(IEnumerable assemblies, IEnumerable paired) + { + var pairedPaths = new HashSet(paired.Select(p => p.FullName)); + return assemblies.Where(a => !pairedPaths.Contains(a.FullName)).ToList(); + } +} diff --git a/src/assembly-differ/Program.cs b/src/assembly-differ/Program.cs index bf7f81e..211e1bd 100644 --- a/src/assembly-differ/Program.cs +++ b/src/assembly-differ/Program.cs @@ -2,6 +2,7 @@ using Nullean.Argh; var app = new ArghApp(); +app.Map(); app.MapAndRootAlias(); return await app.RunAsync(args); diff --git a/src/assembly-differ/Providers/NupkgAssemblyProvider.cs b/src/assembly-differ/Providers/NupkgAssemblyProvider.cs new file mode 100644 index 0000000..7a1b6d2 --- /dev/null +++ b/src/assembly-differ/Providers/NupkgAssemblyProvider.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using NuGet.Frameworks; +using NuGet.Packaging; + +namespace Differ.Providers; + +/// The assemblies a .nupkg file ships for one target framework, unpacked into a folder of their own. +public class NupkgAssemblyProvider : IAssemblyProvider +{ + private readonly string _path; + private readonly NuGetFramework _framework; + + public NupkgAssemblyProvider(string path, NuGetFramework framework) + { + if (!File.Exists(path)) + throw new FileNotFoundException($"no package found at {path}"); + _path = path; + _framework = framework; + } + + public IEnumerable GetAssemblies(HashSet targets) + { + var directory = Path.Combine(Path.GetTempPath(), "differ", "nupkg", Path.GetFileNameWithoutExtension(_path), _framework.GetShortFolderName()); + if (Directory.Exists(directory)) + Directory.Delete(directory, true); + Directory.CreateDirectory(directory); + + using var reader = new PackageArchiveReader(_path); + var group = reader.GetLibItems().FirstOrDefault(g => g.TargetFramework.Equals(_framework)); + if (group is null) + return []; + + var assemblies = new List(); + foreach (var item in group.Items.Where(i => i.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))) + { + if (targets.Count > 0 && !targets.Contains(Path.GetFileNameWithoutExtension(item))) + continue; + var destination = Path.Combine(directory, Path.GetFileName(item)); + using (var source = reader.GetStream(item)) + using (var file = File.Create(destination)) + source.CopyTo(file); + assemblies.Add(new FileInfo(destination)); + } + return assemblies; + } +} + +/// What a .nupkg file says about itself. +public static class Nupkg +{ + public static bool IsPackage(string path) => path.EndsWith(".nupkg", StringComparison.OrdinalIgnoreCase); + + public static (string Id, string Version) Identity(string path) + { + using var reader = new PackageArchiveReader(path); + var identity = reader.GetIdentity(); + return (identity.Id, identity.Version.ToNormalizedString()); + } + + /// The target frameworks the package ships assemblies for: .NET first, then .NET Standard, then .NET Framework, newest first. + public static IReadOnlyList Frameworks(string path) + { + using var reader = new PackageArchiveReader(path); + return reader + .GetLibItems() + .Where(g => g.Items.Any(i => i.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))) + .Select(g => g.TargetFramework) + .OrderByDescending( + f => + f.Framework switch + { + FrameworkConstants.FrameworkIdentifiers.NetCoreApp => 3, + FrameworkConstants.FrameworkIdentifiers.NetStandard => 2, + FrameworkConstants.FrameworkIdentifiers.Net => 1, + _ => 0, + } + ) + .ThenByDescending(f => f.Version) + .ToList(); + } +} diff --git a/src/assembly-differ/README.md b/src/assembly-differ/README.md index 8a2895e..baf16a4 100644 --- a/src/assembly-differ/README.md +++ b/src/assembly-differ/README.md @@ -19,13 +19,14 @@ the `assembly-differ` package itself, not those. ## Quick start -Diff the last release on nuget.org against what you just built, and fail on a breaking change: +Compare the package you just packed with its last release on nuget.org, and fail on a breaking change: ```sh -assembly-differ diff "previous-nuget|MyLib|1.3.0|net8.0" "directory|src/MyLib/bin/Release/net8.0" -t MyLib -f markdown -p major +assembly-differ release build/output/MyLib.1.3.0.nupkg --fail-on major ``` -A diff of Proc 0.13.0 against 0.14.0, which replaced its `Start*` overloads, ends with: +`assembly-differ nuget Proc 0.13.0 0.14.0 -f xml`, a diff of two versions where 0.14.0 replaced the `Start*` +overloads, ends with: ```console @@ -34,21 +35,21 @@ A diff of Proc 0.13.0 against 0.14.0, which replaced its `Start*` overloads, end [diff] Suggested version change: Major ``` -| Spec | Assemblies | +| Command | Compares | |---|---| -| `assembly\|` | one dll | -| `directory\|` | every dll in a directory, matched by file name | -| `nuget\|\|\|[tfm]` | a package from the NuGet sources your NuGet.config lists | -| `previous-nuget\|\|\|[tfm]` | the release on nuget.org before `` | -| `github\|\|\|\|` | a commit, cloned and built | +| `release ` | a `.nupkg`, `.dll` or directory with the release before it on nuget.org | +| `files ` | two local builds: `.dll`s, directories or `.nupkg`s | +| `nuget ` | two published versions | +| `github --build --artifacts ` | a build with an older commit, built with your command | -| Flag | What | +| Option | What | |---|---| -| `-t`, `--target` | only diff these assemblies (repeatable); defaults to every assembly both sides have | -| `-f`, `--format` | `xml` (default), `markdown`, `asciidoc` or `github-comment` | -| `-o`, `--output` | output directory or file; without it the diff only goes to the console | -| `-p`, `--prevent-change` | exit with `4` when the suggested change is at least `patch`, `minor` or `major` | -| `-a`, `--allow-empty-previous-nuget` | succeed when `previous-nuget` finds no earlier release (a first release) | +| `-t`, `--target` | only compare these assemblies (repeatable); defaults to every assembly both sides have | +| `-f`, `--format` | `markdown` (default), `xml`, `asciidoc`, `github-comment` or `json` | +| `-o`, `--output` | a directory or file to write the report to, besides the console | +| `--fail-on` | exit with `4` when the suggested change is at least `patch`, `minor` or `major` | + +`diff` with provider specs, such as `"nuget|Proc|0.13.0"`, still works as before for the builds that call it. It also runs as a GitHub Action (`uses: nullean/assembly-differ@main`) and as a container (`ghcr.io/nullean/assembly-differ`), both without a .NET SDK. diff --git a/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_assemblies.verified.txt b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_assemblies.verified.txt new file mode 100644 index 0000000..a261838 --- /dev/null +++ b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_assemblies.verified.txt @@ -0,0 +1,9 @@ +exit code: 0 +--- stdout +[diff] Difference found: AssemblyProvider:Lib.dll and AssemblyProvider:Lib.dll +## API Changes: `Lib` + +## `Lib.Widget` +### `Draw()` is deleted +[diff] Suggested version change: Major +--- stderr diff --git a/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_directories_for_a_target.verified.txt b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_directories_for_a_target.verified.txt new file mode 100644 index 0000000..2e9e6e1 --- /dev/null +++ b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_directories_for_a_target.verified.txt @@ -0,0 +1,34 @@ +exit code: 0 +--- stdout +[diff] Difference found: DirectoryAssemblyProvider:Lib.dll and DirectoryAssemblyProvider:Lib.dll +{ + "suggestedVersionChange": "Minor", + "breakingChanges": 0, + "assemblies": [ + { + "name": "Lib.dll", + "suggestedVersionChange": "Minor", + "breakingChanges": 0, + "changes": [ + { + "kind": "Type", + "name": "Lib.Widget", + "change": "modified", + "suggestedVersionChange": "Minor", + "changes": [ + { + "kind": "Method", + "name": "Erase()", + "change": "added", + "suggestedVersionChange": "Minor" + } + ] + } + ] + } + ], + "removedAssemblies": [], + "addedAssemblies": [] +} +[diff] Suggested version change: Minor +--- stderr diff --git a/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_packages_on_the_newest_framework_both_ship.verified.txt b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_packages_on_the_newest_framework_both_ship.verified.txt new file mode 100644 index 0000000..1ed71d5 --- /dev/null +++ b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Files_compares_two_packages_on_the_newest_framework_both_ship.verified.txt @@ -0,0 +1,8 @@ +exit code: 0 +--- stdout +[diff] Difference found: NupkgAssemblyProvider:Lib.dll and NupkgAssemblyProvider:Lib.dll +## API Changes: `Lib` + +## `Lib.IShape` is deleted +[diff] Suggested version change: Major +--- stderr diff --git a/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.files.618511ab.verified.txt b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.files.618511ab.verified.txt new file mode 100644 index 0000000..75864ce --- /dev/null +++ b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.files.618511ab.verified.txt @@ -0,0 +1,22 @@ +Usage: assembly-differ files [options] + + Compares two local builds: dlls, directories of dlls, or .nupkg files. + +Arguments: + The old build: a .dll, a directory or a .nupkg. + The new build: a .dll, a directory or a .nupkg. + +Global options: + -h, --help Show help. + +Options: + --framework The target framework to take from a .nupkg, such as net8.0. Defaults to the newest both packages ship. [default: null] + -t, --target [repeatable] Only compare these assemblies, by file name without extension. Repeat it for more than one. + -f, --format The report: markdown, xml, asciidoc, github-comment or json. [default: markdown] [allowed: markdown|xml|asciidoc|github-comment|json] + -o, --output A directory or file to write the report to, besides the console. + --fail-on Exit with code 4 when the suggested version change is at least this: none (never), patch, minor or major. [default: none] [allowed: none|patch|minor|major] + +Examples: + assembly-differ files bin/1.2.0/MyLib.dll bin/1.3.0/MyLib.dll + + assembly-differ files MyLib.1.2.0.nupkg MyLib.1.3.0.nupkg --framework net8.0 diff --git a/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.github.64ea231d.verified.txt b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.github.64ea231d.verified.txt new file mode 100644 index 0000000..674a1d1 --- /dev/null +++ b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.github.64ea231d.verified.txt @@ -0,0 +1,22 @@ +Usage: assembly-differ github --build --artifacts [options] + + Compares a new build with an older commit of a GitHub repository, built with the command you give. + +Arguments: + The repository as owner/name. + The commit, branch or tag to build as the old version. + The new build: a .dll or a directory. + +Global options: + -h, --help Show help. + +Options: + --build [required] The command that builds the old commit, run in its checkout. + --artifacts [required] Where the build leaves the assemblies, relative to the checkout. + -t, --target [repeatable] Only compare these assemblies, by file name without extension. Repeat it for more than one. + -f, --format The report: markdown, xml, asciidoc, github-comment or json. [default: markdown] [allowed: markdown|xml|asciidoc|github-comment|json] + -o, --output A directory or file to write the report to, besides the console. + --fail-on Exit with code 4 when the suggested version change is at least this: none (never), patch, minor or major. [default: none] [allowed: none|patch|minor|major] + +Examples: + assembly-differ github nullean/proc 0.13.0 src/Proc/bin/Release/netstandard2.0 --build "dotnet build -c Release" --artifacts src/Proc/bin/Release/netstandard2.0 diff --git a/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.nuget.84cf3223.verified.txt b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.nuget.84cf3223.verified.txt new file mode 100644 index 0000000..ba73cdc --- /dev/null +++ b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.nuget.84cf3223.verified.txt @@ -0,0 +1,21 @@ +Usage: assembly-differ nuget [options] + + Compares two published versions of a package. + +Arguments: + The package id. + The old version. + The new version. + +Global options: + -h, --help Show help. + +Options: + --framework The target framework to compare, such as net8.0. Defaults to the first the package ships. [default: null] + -t, --target [repeatable] Only compare these assemblies, by file name without extension. Repeat it for more than one. + -f, --format The report: markdown, xml, asciidoc, github-comment or json. [default: markdown] [allowed: markdown|xml|asciidoc|github-comment|json] + -o, --output A directory or file to write the report to, besides the console. + --fail-on Exit with code 4 when the suggested version change is at least this: none (never), patch, minor or major. [default: none] [allowed: none|patch|minor|major] + +Examples: + assembly-differ nuget Proc 0.13.0 0.14.0 diff --git a/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.release.2196f031.verified.txt b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.release.2196f031.verified.txt new file mode 100644 index 0000000..6529cfa --- /dev/null +++ b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.release.2196f031.verified.txt @@ -0,0 +1,28 @@ +Usage: assembly-differ release [options] + + Compares a new build with the release before it on nuget.org. + +Arguments: + The new build: a .nupkg, a .dll or a directory. + +Global options: + -h, --help Show help. + +Options: + --package The package id; read from a .nupkg when not given. [default: null] + --version The version being released; read from a .nupkg when not given. [default: null] + --framework The target framework to compare, such as net8.0. Defaults to the newest the .nupkg ships. [default: null] + -t, --target [repeatable] Only compare these assemblies, by file name without extension. Repeat it for more than one. + -f, --format The report: markdown, xml, asciidoc, github-comment or json. [default: markdown] [allowed: markdown|xml|asciidoc|github-comment|json] + -o, --output A directory or file to write the report to, besides the console. + --fail-on Exit with code 4 when the suggested version change is at least this: none (never), patch, minor or major. [default: none] [allowed: none|patch|minor|major] + +Notes: + + Give a .nupkg and the package id and version come from it; for a .dll or a directory, pass --package and --version. + The release compared with is the newest one before that version. + +Examples: + assembly-differ release build/output/MyLib.1.3.0.nupkg --fail-on major + + assembly-differ release src/MyLib/bin/Release/net8.0 --package MyLib --version 1.3.0 -t MyLib diff --git a/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.root.460a906e.verified.txt b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.root.460a906e.verified.txt new file mode 100644 index 0000000..99d96bf --- /dev/null +++ b/tests/assembly-differ.Tests/.snapshots/CommandsTests/Help.root.460a906e.verified.txt @@ -0,0 +1,16 @@ +Usage: assembly-differ [options] + + (default command) + Compares the public API of two versions of a library and suggests the version change it calls for. Pick a command for where the versions come from; diff with provider specs, such as nuget|Proc|0.13.0, still works for existing builds. + +Global options: + -h, --help Show help. + --version Show version. + +Commands: + files Compares two local builds: dlls, directories of dlls, or .nupkg + files. + github Compares a new build with an older commit of a GitHub repository, + built with the command you give. + nuget Compares two published versions of a package. + release Compares a new build with the release before it on nuget.org. diff --git a/tests/assembly-differ.Tests/CommandsTests.cs b/tests/assembly-differ.Tests/CommandsTests.cs new file mode 100644 index 0000000..c8be44a --- /dev/null +++ b/tests/assembly-differ.Tests/CommandsTests.cs @@ -0,0 +1,124 @@ +using System.IO.Compression; +using AwesomeAssertions; +using Nullean.Snapshots; + +namespace Differ.Tests; + +/// The command for each source: files, nuget, release and github. +public class CommandsTests +{ + public static IEnumerable Helps() => ["", "files", "nuget", "release", "github"]; + + [Test] + [MethodDataSource(nameof(Helps))] + public async Task Help(string command) + { + var result = await Cli.RunAsync(command.Length == 0 ? ["--help"] : [command, "--help"]); + + result.Out.Should().MatchSnapshot(name: command.Length == 0 ? "root" : command); + } + + [Test] + public async Task Files_compares_two_assemblies() + { + using var fixture = Scenarios.Create("method-removed"); + + var result = await Cli.RunAsync("files", fixture.OldAssembly, fixture.NewAssembly); + + Report.Of(result, fixture).Should().MatchSnapshot(); + } + + [Test] + public async Task Files_compares_two_directories_for_a_target() + { + using var fixture = Scenarios.Create("method-added"); + + var result = await Cli.RunAsync("files", fixture.OldDirectory, fixture.NewDirectory, "-t", "Lib", "-f", "json"); + + Report.Of(result, fixture).Should().MatchSnapshot(); + } + + [Test] + public async Task Files_compares_two_packages_on_the_newest_framework_both_ship() + { + using var fixture = Scenarios.Create("type-removed"); + var oldPackage = Package(fixture, "old.nupkg", "1.0.0", fixture.OldAssembly, "netstandard2.0", "net8.0"); + var newPackage = Package(fixture, "new.nupkg", "1.1.0", fixture.NewAssembly, "net8.0", "net10.0"); + + var result = await Cli.RunAsync("files", oldPackage, newPackage); + + Report.Of(result, fixture).Should().MatchSnapshot(); + } + + [Test] + public async Task Files_fails_on_packages_without_a_framework_in_common() + { + using var fixture = Scenarios.Create("unchanged"); + var oldPackage = Package(fixture, "old.nupkg", "1.0.0", fixture.OldAssembly, "netstandard2.0"); + var newPackage = Package(fixture, "new.nupkg", "1.1.0", fixture.NewAssembly, "net8.0"); + + var result = await Cli.RunAsync("files", oldPackage, newPackage); + + result.ExitCode.Should().Be(1); + result.Error.Should().Contain("no target framework in common; pass --framework"); + } + + [Test] + public async Task Release_needs_a_package_and_version_for_a_dll() + { + using var fixture = Scenarios.Create("unchanged"); + + var result = await Cli.RunAsync("release", fixture.NewAssembly); + + result.ExitCode.Should().Be(1); + result.Error.Trim().Should().Be("[diff] pass --package and --version, or a .nupkg to read them from"); + } + + [Test] + [NotInParallel(nameof(NuGetProviderTests))] + public async Task Release_compares_a_package_with_the_release_before_it() + { + // Proc 0.14.0 from nuget.org, compared with 0.13.0, the release before it; 0.14.0 changed signatures + using var fixture = Scenarios.Create("unchanged"); + var package = Path.Combine(fixture.Root, "proc.0.14.0.nupkg"); + using (var http = new HttpClient()) + await File.WriteAllBytesAsync(package, await http.GetByteArrayAsync("https://api.nuget.org/v3-flatcontainer/proc/0.14.0/proc.0.14.0.nupkg")); + + var result = await Cli.RunAsync("release", package, "-f", "json", "--fail-on", "major"); + + result.ExitCode.Should().Be(4, result.Out + result.Error); + result.Out.Should().Contain("Found previous nuget package found for Proc 0.14.0: 0.13.0").And.Contain("\"suggestedVersionChange\": \"Major\""); + } + + [Test] + [NotInParallel(nameof(NuGetProviderTests))] + public async Task NuGet_compares_two_published_versions() + { + // Proc 0.13.0 marks NoWrapInThread obsolete, and changes nothing else + var result = await Cli.RunAsync("nuget", "Proc", "0.12.0", "0.13.0", "-t", "proc"); + + result.ExitCode.Should().Be(0, result.Error); + result.Out.Should().Contain("### `NoWrapInThread`\nAttribute `System.ObsoleteAttribute::.ctor(System.String)` is added."); + result.Out.Should().Contain("[diff] Suggested version change: Minor"); + } + + /// Writes a .nupkg holding the assembly once for every framework given. + private static string Package(Fixture fixture, string fileName, string version, string assembly, params string[] frameworks) + { + var path = Path.Combine(fixture.Root, fileName); + using var zip = ZipFile.Open(path, ZipArchiveMode.Create); + var nuspec = zip.CreateEntry("Lib.nuspec"); + using (var writer = new StreamWriter(nuspec.Open())) + writer.Write( + $""" + + + Lib{version}teststests + + """ + ); + foreach (var framework in frameworks) + zip.CreateEntryFromFile(assembly, $"lib/{framework}/Lib.dll"); + return path; + } +}