Skip to content

Fix error if no matching packages found #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2024

Conversation

martincostello
Copy link
Contributor

In the scenario where a project is using prerelease packages but specifies --pre-release:Never and there are no stable packages available, dotnet outdated would return an error and list blank versions to upgrade to.

Instead, if no packages are found for upgrade, report the package itself as the latest version.

For example, running dotnet-outdated against martincostello/website@99fad95 (which is currently using .NET 9 RC1 and no stable version of .NET 9 is yet available) gives the following output:

dotnet outdated --pre-release:Never
» C:\Coding\martincostello\website\perf\Website.Benchmarks\Website.Benchmarks.csproj
  [net9.0]
  StyleCop.Analyzers  1.2.0-beta.556 ->

» C:\Coding\martincostello\website\src\Website\Website.csproj
  [net9.0]
  Microsoft.AspNetCore.AzureAppServices.HostingStartup  9.0.0-rc.1.24452.1 ->
  OpenTelemetry.Resources.Azure                         1.0.0-beta.8       ->
  OpenTelemetry.Resources.Container                     1.0.0-beta.9       ->
  StyleCop.Analyzers                                    1.2.0-beta.556     ->

» C:\Coding\martincostello\website\tests\Website.EndToEndTests\Website.EndToEndTests.csproj
  [net9.0]
  StyleCop.Analyzers  1.2.0-beta.556 ->

» C:\Coding\martincostello\website\tests\Website.Tests.Shared\Website.Tests.Shared.csproj
  [net9.0]
  Microsoft.Playwright  1.46.0         -> 1.47.0
  StyleCop.Analyzers    1.2.0-beta.556 ->

» C:\Coding\martincostello\website\tests\Website.Tests\Website.Tests.csproj
  [net9.0]
  Microsoft.AspNetCore.Mvc.Testing  9.0.0-rc.1.24452.1 ->
  StyleCop.Analyzers                1.2.0-beta.556     ->

Errors occurred while analyzing dependencies for some of your projects. Are you sure you can connect to all your configured NuGet servers?

Unable to find DOTNET_HOST_PATH environment variable. If you use credential providers for your NuGet sources you need to have this set to the path to the `dotnet` executable.

Version color legend:
<red>   : Major version update or pre-release version. Possible breaking changes.
<yellow>: Minor version update. Backwards-compatible features added.
<green> : Patch version update. Backwards-compatible bug fixes.

You can upgrade packages to the latest version by passing the -u or -u:prompt option.
Elapsed: 00:00:03.4100881

With the change, the output is the following:

dotnet outdated --pre-release:Never
» Website.Tests.Shared
  [net9.0]
  Microsoft.Playwright  1.46.0 -> 1.47.0

Version color legend:
<red>   : Major version update or pre-release version. Possible breaking changes.
<yellow>: Minor version update. Backwards-compatible features added.
<green> : Patch version update. Backwards-compatible bug fixes.

You can upgrade packages to the latest version by passing the -u or -u:prompt option.
Elapsed: 00:00:08.5505735

In the scenario where a project is using prerelease packages but specifies `--pre-release:Never` and there are no stable packages available, dotnet outdated would return an error and list blank versions to upgrade to. Instead, if no packages are found for upgrade, report the package itself as the latest version.
Bump System.Formats.Asn1 to resolve NU1903 warning for GHSA-447r-wph3-92pm.
Improve the exception that occurs if a solution has a `NU1604` warning and tries to pass a `VersionRange` with `MinVersion == null` to `VersionRange.ctor(VersionRange, FloatRange)`.
@martincostello
Copy link
Contributor Author

Also includes a change to improve the error if run on a project with NU1604 warnings:

dotnet outdated -u
Analyzing dependencies...Unhandled exception. System.ArgumentNullException: Parameter 'minVersion' cannot be null when parameter 'floatRange' is not null. (Parameter 'minVersion')
   at NuGet.Versioning.VersionRange..ctor(NuGetVersion minVersion, Boolean includeMinVersion, NuGetVersion maxVersion, Boolean includeMaxVersion, FloatRange floatRange, String originalString)
   at NuGet.Versioning.VersionRange..ctor(VersionRange range, FloatRange floatRange)
   at DotNetOutdated.Core.Services.NuGetPackageResolutionService.ResolvePackageVersions(String packageName, NuGetVersion referencedVersion, IEnumerable`1 sources, VersionRange currentVersionRange, VersionLock versionLock, PrereleaseReporting prerelease, String prereleaseLabel, NuGetFramework targetFrameworkName, String projectFilePath, Boolean isDevelopmentDependency, Int32 olderThanDays, Boolean ignoreFailedSources) in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated.Core/Services/NuGetPackageResolutionService.cs:line 98
   at DotNetOutdated.Program.AddOutdatedDependencyIfNeeded(Project project, TargetFramework targetFramework, Dependency dependency, ConcurrentBag`1 outdatedDependencies) in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated/Program.cs:line 504
   at DotNetOutdated.Program.AddOutdatedFrameworkIfNeeded(TargetFramework targetFramework, Project project, ConcurrentBag`1 outdatedFrameworks) in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated/Program.cs:line 491
   at DotNetOutdated.Program.AddOutdatedProjectsIfNeeded(Project project, ConcurrentBag`1 outdatedProjects) in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated/Program.cs:line 460
   at DotNetOutdated.Program.AnalyzeDependencies(List`1 projects, IConsole console) in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated/Program.cs:line 425
   at DotNetOutdated.Program.OnExecute(CommandLineApplication app, IConsole console) in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated/Program.cs:line 198
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.InvokeAsync(MethodInfo method, Object instance, Object[] arguments)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at DotNetOutdated.Program.Main(String[] args) in /home/runner/work/dotnet-outdated/dotnet-outdated/src/DotNetOutdated/Program.cs:line 141

@slang25 slang25 merged commit 1e74aca into dotnet-outdated:master Oct 2, 2024
9 checks passed
@martincostello martincostello deleted the fix-error branch October 2, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants