diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs index aaf9936d51..11fafd68a6 100644 --- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs +++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs @@ -64,6 +64,7 @@ public static class ApplicationParameters public static int DefaultWaitForExitInSeconds = 2700; public static readonly string[] ConfigFileExtensions = new string[] {".autoconf",".config",".conf",".cfg",".jsc",".json",".jsonp",".ini",".xml",".yaml"}; + public static readonly string[] ShimDirectorFileExtensions = new string[] {".gui",".ignore"}; public static readonly string HashProviderFileTooBig = "UnableToDetectChanges_FileTooBig"; public static readonly string HashProviderFileLocked = "UnableToDetectChanges_FileLocked"; diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 092431b58e..63da94e3ef 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -596,6 +596,7 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu { rename_legacy_package_version(config, installedPackage, pkgInfo); backup_existing_version(config, installedPackage, pkgInfo); + remove_shim_directors(config, installedPackage, pkgInfo); if (config.Force && (installedPackage.Version == availablePackage.Version)) { FaultTolerance.try_catch_with_logging_exception( @@ -738,6 +739,43 @@ public void backup_changed_files(string packageInstallPath, ChocolateyConfigurat } } + /// + /// Remove the shimgen director files from the package. + /// These are .gui/.ignore files that may have been created during the installation + /// process and won't be pulled by the nuget package replacement. + /// This usually happens when package maintainers haven't been very good about how + /// they create the files in the past (not using force with new-item typically throws + /// an error if the file exists). + /// + /// The configuration. + /// The installed package. + /// The package information. + private void remove_shim_directors(ChocolateyConfiguration config, IPackage installedPackage, ChocolateyPackageInformation pkgInfo) + { + var pathResolver = NugetCommon.GetPathResolver(config, NugetCommon.GetNuGetFileSystem(config, _nugetLogger)); + var pkgInstallPath = pathResolver.GetInstallPath(installedPackage); + if (!_fileSystem.directory_exists(pkgInstallPath)) + { + var chocoPathResolver = pathResolver as ChocolateyPackagePathResolver; + if (chocoPathResolver != null) + { + chocoPathResolver.UseSideBySidePaths = !chocoPathResolver.UseSideBySidePaths; + pkgInstallPath = chocoPathResolver.GetInstallPath(installedPackage); + } + } + + if (_fileSystem.directory_exists(pkgInstallPath)) + { + var shimDirectorFiles = _fileSystem.get_files(pkgInstallPath, ApplicationParameters.ShimDirectorFileExtensions, SearchOption.AllDirectories); + foreach (var file in shimDirectorFiles.or_empty_list_if_null()) + { + FaultTolerance.try_catch_with_logging_exception( + () => _fileSystem.delete_file(file), + "Error deleting shim director file"); + } + } + } + public void uninstall_noop(ChocolateyConfiguration config, Action continueAction) { var results = uninstall_run(config, continueAction, performAction: false);