Skip to content

Commit

Permalink
(chocolatey#2981) Deprecate install with direct file path
Browse files Browse the repository at this point in the history
This functionality is unneeded, as choco can pack the packages with
another command anyway, and doing it this way complicates the install
code path, making things more error-prone and difficut to maintain.
We plan to remove this in v2.0, so deprecating it now to give folks a
heads up.
  • Loading branch information
vexx32 committed Feb 13, 2023
1 parent 6583bf6 commit 33056d0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ Side by side installations has been deprecated and will be removed in v2.0.0.
Instead of using side by side installations, distinct packages should be created
if similar functionality is needed going forward.
");
"chocolatey".Log().Warn(NugetService.InstallWithFilePathDeprecationMessage);

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
"chocolatey".Log().Info(@"
Expand Down Expand Up @@ -302,7 +303,7 @@ choco install nodejs.install --version 0.10.35
choco install git -s ""'https://somewhere/out/there'""
choco install git -s ""'https://somewhere/protected'"" -u user -p pass
Choco can also install directly from a nuspec/nupkg file. This aids in
(DEPRECATED) Choco can also install directly from a nuspec/nupkg file. This aids in
testing packages:
choco install <path/to/nuspec>
Expand Down
11 changes: 11 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ private IDateTime DateTime
get { return datetime_initializer.Value; }
}

internal const string InstallWithFilePathDeprecationMessage = @"
The ability to specify a direct path to a .nuspec or .nupkg file for installation
is deprecated and will be removed in v2.0.0. Instead of using the full path
to a .nupkg file, use the --source option to specify the containing directory,
and ensure any packages have been packed into a .nupkg file before attempting to
install them.
";

/// <summary>
/// Initializes a new instance of the <see cref="NugetService" /> class.
/// </summary>
Expand Down Expand Up @@ -391,6 +399,9 @@ public virtual ConcurrentDictionary<string, PackageResult> install_run(Chocolate
var packageName = packageNames.DefaultIfEmpty(string.Empty).FirstOrDefault();
if (packageName.EndsWith(Constants.PackageExtension) || packageName.EndsWith(Constants.ManifestExtension))
{
this.Log().Warn(ChocolateyLoggers.Important, "DEPRECATION WARNING");
this.Log().Warn(InstallWithFilePathDeprecationMessage);

this.Log().Debug("Updating source and package name to handle *.nupkg or *.nuspec file.");
packageNames.Clear();

Expand Down
11 changes: 10 additions & 1 deletion tests/chocolatey-tests/commands/choco-install.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Import-Module helpers/common-helpers
Import-Module helpers/common-helpers

# https://github.com/chocolatey/choco/blob/master/src/chocolatey.tests.integration/scenarios/InstallScenarios.cs

Expand Down Expand Up @@ -1218,6 +1218,15 @@ Describe "choco install" -Tag Chocolatey, InstallCommand {
$Output.ExitCode | Should -Be 0
}

It "Warns that this functionality is deprecated" {
$pattern = @(
"The ability to specify a direct path to a .nuspec or .nupkg file for installation"
"is deprecated and will be removed in v2.0.0."
) -join "\r?\n"

$Output.String | Should -Match $pattern
}

It "Installed a package to the lib directory" {
"$env:ChocolateyInstall\lib\$PackageUnderTest" | Should -Exist
}
Expand Down

0 comments on commit 33056d0

Please sign in to comment.