From 06e666f8bedf390cd768cd612420dd0734cb237f Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Fri, 16 Apr 2021 22:23:22 -0500 Subject: [PATCH] (#2241) Set install location to package dir for portable packages Set the install location to the package folder under lib for nuget packages that do not have a chocolateyinstall.ps1. This will display the install location correctly for portable packages that just include binary(s) that get automatically shimmed. --- .../services/ChocolateyPackageService.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 1abaf25512..c1246c4315 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -342,6 +342,9 @@ public virtual void handle_package_result(PackageResult packageResult, Chocolate var pkgInfo = get_package_information(packageResult, config); + // initialize this here so it can be used for the install location later + bool powerShellRan = false; + if (packageResult.Success && config.Information.PlatformType == PlatformType.Windows) { if (!config.SkipPackageInstallProvider) @@ -349,7 +352,7 @@ public virtual void handle_package_result(PackageResult packageResult, Chocolate var installersBefore = _registryService.get_installer_keys(); var environmentBefore = get_environment_before(config, allowLogging: false); - var powerShellRan = _powershellService.install(config, packageResult); + powerShellRan = _powershellService.install(config, packageResult); if (powerShellRan) { // we don't care about the exit code @@ -413,6 +416,11 @@ public virtual void handle_package_result(PackageResult packageResult, Chocolate } } + if (!powerShellRan && string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation))) + { + Environment.SetEnvironmentVariable(ApplicationParameters.Environment.ChocolateyPackageInstallLocation, packageResult.InstallLocation, EnvironmentVariableTarget.Process); + } + if (pkgInfo.RegistrySnapshot != null && pkgInfo.RegistrySnapshot.RegistryKeys.Any(k => !string.IsNullOrWhiteSpace(k.InstallLocation))) { var key = pkgInfo.RegistrySnapshot.RegistryKeys.FirstOrDefault(k => !string.IsNullOrWhiteSpace(k.InstallLocation));