adamralph/minver

Installing 4.3.0 with Nuke build causes multiple versions to be referenced

henry-js opened this issue · 2 comments

Version(s)

4.3.0
The version(s) in which you have observed the bug.

To reproduce

Run nuke :add-package minver-cli --version 4.3.0 in a repository with a build project
Steps to reproduce the behaviour:

  1. Create repository with a console app in src
  2. Install nuke global tool dotnet tool install nuke.globaltool --global
  3. Run nuke and setup build project
  4. Run nuke :add-package minver-cli --version 4.3.0 in repository
  5. Add Print target that should print minver semantic version
using Nuke.Common.Tools.MinVer;
class Build : NukeBuild
{
...
  [MinVer]
  readonly MinVer Minver;
  Target Print => _ => _
    .Executes(() =>
  {
      Log.Information("Minver: {Value}", Minver.Version);
  });
...
}
...
  1. Run nuke Print

Expected behaviour

Should receive output similar to in 4.2.0:

❯ nuke Print --no-logo                                                                                                                                                                                                                                                                                                  
PowerShell Desktop version 5.1.22621.2506
Microsoft (R) .NET SDK version 8.0.200
13:57:18 [INF] > "C:\Program Files\dotnet\dotnet.exe" C:\Users\jhenry\.nuget\packages\minver-cli\4.2.0\tools\net6.0\any\minver-cli.dll

╬══════════
║ Print
╬══

13:57:18 [INF] Minver: 1.0.1-alpha.0.5

═══════════════════════════════════════
Target             Status      Duration
───────────────────────────────────────
Print              Succeeded     < 1sec
───────────────────────────────────────
Total                            < 1sec
═══════════════════════════════════════

Build succeeded on 22/02/2024 13:57:18. \(^ᴗ^)/

Actual behaviour

❯ nuke Print --no-logo                                                                                                                                                                                                                                                                                                  
PowerShell Desktop version 5.1.22621.2506
Microsoft (R) .NET SDK version 8.0.200
13:58:53 [WRN] Could not inject value for Build.Minver
System.Exception: Missing package reference/download.
Run one of the following commands:
  - nuke :add-package minver-cli --version 4.3.0
 ---> System.InvalidOperationException: Package 'minver-cli' is referenced with multiple versions. Use NuGetPackageResolver and SetToolPath.
 ---> System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Nuke.Common.Tooling.NuGetPackageResolver.GetGlobalInstalledPackage(String packageId, VersionRange versionRange, AbsolutePath packagesConfigFile, Nullable`1 includePrereleases) in /_/source/Nuke.Tooling/NuGetPackageResolver.cs:line 217
   at Nuke.Common.Tooling.NuGetPackageResolver.GetGlobalInstalledPackage(String packageId, String version, AbsolutePath packagesConfigFile) in /_/source/Nuke.Tooling/NuGetPackageResolver.cs:line 182
   at Nuke.Common.Tooling.NuGetPackageResolver.<>c__DisplayClass3_0.<GetLocalInstalledPackagesFromAssetsFile>b__1(ValueTuple`2 x) in /_/source/Nuke.Tooling/NuGetPackageResolver.cs:line 100
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()
   at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Nuke.Common.Utilities.Collections.EnumerableExtensions.SingleOrDefaultOrError[T](IEnumerable`1 enumerable, Func`2 predicate, String message) in /_/source/Nuke.Utilities/Collections/Enumerable.SingleOrDefaultOrError.cs:line 19
   --- End of inner exception stack trace ---
   at Nuke.Common.Utilities.Collections.EnumerableExtensions.SingleOrDefaultOrError[T](IEnumerable`1 enumerable, Func`2 predicate, String message) in /_/source/Nuke.Utilities/Collections/Enumerable.SingleOrDefaultOrError.cs:line 23
   at Nuke.Common.Tooling.NuGetPackageResolver.GetLocalInstalledPackage(String packageId, AbsolutePath packagesConfigFile, String version, Boolean resolveDependencies) in /_/source/Nuke.Tooling/NuGetPackageResolver.cs:line 30
   at Nuke.Common.Tooling.NuGetToolPathResolver.<>c__DisplayClass5_1.<GetPackageDirectory>b__5() in /_/source/Nuke.Tooling/NuGetToolPathResolver.cs:line 92
   at Nuke.Common.Tooling.NuGetToolPathResolver.<>c.<GetPackageDirectory>b__5_1(Func`1 x) in /_/source/Nuke.Tooling/NuGetToolPathResolver.cs:line 102
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Nuke.Common.Tooling.NuGetToolPathResolver.GetPackageDirectory(String[] packageIds, String version) in /_/source/Nuke.Tooling/NuGetToolPathResolver.cs:line 85
   --- End of inner exception stack trace ---
   at Nuke.Common.Assert.Fail(String message, Exception exception) in /_/source/Nuke.Utilities/Assert.cs:line 28
   at Nuke.Common.Tooling.NuGetToolPathResolver.GetPackageDirectory(String[] packageIds, String version) in /_/source/Nuke.Tooling/NuGetToolPathResolver.cs:line 145
   at Nuke.Common.Tooling.NuGetToolPathResolver.GetPackageExecutable(String packageId, String packageExecutable, String version, String framework) in /_/source/Nuke.Tooling/NuGetToolPathResolver.cs:line 29
   at Nuke.Common.Tools.MinVer.MinVerTasks.GetToolPath(String framework) in /_/source/Nuke.Common/Tools/MinVer/MinVerTasks.cs:line 15
   at Nuke.Common.Tools.MinVer.MinVerSettings.GetProcessToolPath() in /_/source/Nuke.Common/Tools/MinVer/MinVerTasks.cs:line 48
   at Nuke.Common.Tools.MinVer.MinVerSettings.get_ProcessToolPath() in /_/source/Nuke.Common/Tools/MinVer/MinVer.Generated.cs:line 122
   at Nuke.Common.Tooling.ProcessTasks.StartProcess(ToolSettings toolSettings) in /_/source/Nuke.Tooling/ProcessTasks.cs:line 58
   at Nuke.Common.Tools.MinVer.MinVerTasks.MinVer(MinVerSettings toolSettings) in /_/source/Nuke.Common/Tools/MinVer/MinVer.Generated.cs:line 67
   at Nuke.Common.Tools.MinVer.MinVerTasks.MinVer(Configure`1 configurator) in /_/source/Nuke.Common/Tools/MinVer/MinVer.Generated.cs:line 88
   at Nuke.Common.Tools.MinVer.MinVerAttribute.GetValue(MemberInfo member, Object instance) in /_/source/Nuke.Common/Tools/MinVer/MinVerAttribute.cs:line 29
   at Nuke.Common.ValueInjection.ValueInjectionAttributeBase.TryGetValue(MemberInfo member, Object instance) in /_/source/Nuke.Build/Execution/Extensibility/ValueInjectionAttributeBase.cs:line 26

╬══════════
║ Print
╬══

13:58:53 [ERR] Target Print has thrown an exception
System.NullReferenceException: Object reference not set to an instance of an object.
   at Build.<get_Print>b__10_1() in C:\Users\jhenry\source\repos\commitizen.NET\build\Build.cs:line 46
   at Nuke.Common.Execution.BuildExecutor.<>c.<Execute>b__4_2(Action x) in /_/source/Nuke.Build/Execution/BuildExecutor.cs:line 119
   at System.Collections.Generic.List`1.ForEach(Action`1 action)
   at Nuke.Common.Execution.BuildExecutor.Execute(NukeBuild build, ExecutableTarget target, IReadOnlyCollection`1 previouslyExecutedTargets, Boolean failureMode) in /_/source/Nuke.Build/Execution/BuildExecutor.cs:line 119

╬══════════════════════
║ Errors & Warnings
╬═════════════

[WRN] : Could not inject value for Build.Minver
[ERR] Print: Target Print has thrown an exception

═══════════════════════════════════════
Target             Status      Duration
───────────────────────────────────────
Print              Failed        < 1sec   // NullReferenceException: Object reference not set to an instance of an object.
───────────────────────────────────────
Total                            < 1sec
═══════════════════════════════════════

Build failed on 22/02/2024 13:58:53. (╯°□°)╯︵ ┻━┻

Workarounds

Reverting back to 4.2.0 resolves the issue

Why do you feel this is MinVer specific?
Have you looked at the package difference in NuGet Package explorer (I'd be surprised if there were any structural changes)

Nuke seems to be the major moving part here, and I'm not yet convinced this is a bug in MinVer. Moving to a discussion for now. If it is proven that there is a bug in MinVer then we can address it.