Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,16 @@ private List<PSResourceInfo> InstallPackages(
}
}

string depPkgNameVersion = $"{depPkg.Name}{depPkg.Version.ToString()}";
if (_packagesOnMachine.Contains(depPkgNameVersion) && !depPkg.IsPrerelease)
{
// if a dependency package is already installed, do not install it again.
// to determine if the package version is already installed, _packagesOnMachine is used but it only contains name, version info, not version with prerelease info
// if the dependency package is found to be prerelease, it is safer to install it (and worse case it reinstalls)
_cmdletPassedIn.WriteVerbose($"Dependency '{depPkg.Name}' with version '{depPkg.Version}' is already installed.");
continue;
}

packagesHash = BeginPackageInstall(
searchVersionType: VersionType.SpecificVersion,
specificVersion: depVersion,
Expand Down
5 changes: 4 additions & 1 deletion src/code/UpdatePSResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public sealed class UpdatePSResource : PSCmdlet
{
#region Members
private List<string> _pathsToInstallPkg;
private HashSet<string> _packagesOnMachine;
private CancellationTokenSource _cancellationTokenSource;
private FindHelper _findHelper;
private InstallHelper _installHelper;
Expand Down Expand Up @@ -157,6 +158,8 @@ protected override void BeginProcessing()
RepositorySettings.CheckRepositoryStore();

_pathsToInstallPkg = Utils.GetAllInstallationPaths(this, Scope);
List<string> pathsToSearch = Utils.GetAllResourcePaths(this, Scope);
_packagesOnMachine = Utils.GetInstalledPackages(pathsToSearch, this);
_cancellationTokenSource = new CancellationTokenSource();
var networkCred = Credential != null ? new NetworkCredential(Credential.UserName, Credential.Password) : null;

Expand Down Expand Up @@ -216,7 +219,7 @@ protected override void ProcessRecord()
pathsToInstallPkg: _pathsToInstallPkg,
scope: Scope,
tmpPath: _tmpPath,
pkgsInstalled: new HashSet<string>(StringComparer.InvariantCultureIgnoreCase));
pkgsInstalled: _packagesOnMachine);

if (PassThru)
{
Expand Down
Loading