diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index 8abc5f06e1..f945bc6503 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -162,6 +162,10 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon "Stop On First Package Failure - stop running install, upgrade or uninstall on first package failure instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.StopOnFirstPackageFailure, configuration.Features.StopOnFirstPackageFailure.to_string()), option => configuration.Features.StopOnFirstPackageFailure = option != null ) + .Add("exclude-pre|exclude-prerelease|exclude-prereleases", + "Exclude Prerelease - Should prerelease be ignored for upgrades? Will be ignored if you pass `--pre`. Available in 0.10.4+.", + option => configuration.UpgradeCommand.ExcludePrerelease = option != null + ) ; } diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs index cf5d62e22e..b558854dd5 100644 --- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs +++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs @@ -393,6 +393,7 @@ public sealed class UpgradeCommandConfiguration public bool FailOnNotInstalled { get; set; } public bool NotifyOnlyAvailableUpgrades { get; set; } public string PackageNamesToSkip { get; set; } + public bool ExcludePrerelease { get; set; } } [Serializable] diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 48a60de2a0..0afa51eec4 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -603,8 +603,17 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu var pkgInfo = _packageInfoService.get_package_information(installedPackage); bool isPinned = pkgInfo != null && pkgInfo.IsPinned; + // if we have a prerelease installed, we want to have it upgrade based on newer prereleases + var originalPrerelease = config.Prerelease; + if (!string.IsNullOrWhiteSpace(installedPackage.Version.SpecialVersion) && !config.UpgradeCommand.ExcludePrerelease) + { + // this is a prerelease - opt in for newer prereleases. + config.Prerelease = true; + } IPackage availablePackage = packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false); + config.Prerelease = originalPrerelease; + if (availablePackage == null) { string logMessage = "{0} was not found with the source(s) listed.{1} If you specified a particular version and are receiving this message, it is possible that the package name exists but the version does not.{1} Version: \"{2}\"; Source(s): \"{3}\"".format_with(packageName, Environment.NewLine, config.Version, config.Sources);