Skip to content

Commit

Permalink
Fixed restore from CLI when packages need to be updated (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
igor84 authored Feb 1, 2025
1 parent 81dc663 commit 54c6f94
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/NuGetForUnity/Editor/NugetPackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private static PackageInstallOperationResult Install(
installedPackage.Version,
package.Version,
package.Version);
return NugetPackageUpdater.UpdateWithInformation(installedPackage, package, refreshAssets);
return NugetPackageUpdater.UpdateWithInformation(installedPackage, package, refreshAssets, isSlimRestoreInstall);
}

if (comparisonResult > 0)
Expand All @@ -131,7 +131,7 @@ private static PackageInstallOperationResult Install(
installedPackage.Id,
installedPackage.Version,
package.Version);
return NugetPackageUpdater.UpdateWithInformation(installedPackage, package, refreshAssets);
return NugetPackageUpdater.UpdateWithInformation(installedPackage, package, refreshAssets, isSlimRestoreInstall);
}

NugetLogger.LogVerbose(
Expand Down
7 changes: 4 additions & 3 deletions src/NuGetForUnity/Editor/NugetPackageUninstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ public static class NugetPackageUninstaller
/// <param name="package">The NugetPackage to uninstall.</param>
/// <param name="uninstallReason">The reason uninstall is being called.</param>
/// <param name="refreshAssets">True to force Unity to refresh its Assets folder. False to temporarily ignore the change. Defaults to true.</param>
public static void Uninstall([NotNull] INugetPackageIdentifier package, PackageUninstallReason uninstallReason, bool refreshAssets = true)
/// <param name="isSlimRestore">True if uninstall needs to be done as part of slim restore operation.</param>
public static void Uninstall([NotNull] INugetPackageIdentifier package, PackageUninstallReason uninstallReason, bool refreshAssets = true, bool isSlimRestore = false)
{
// Checking for pre-imported packages also ensures that the pre-imported package list is up-to-date before we uninstall packages.
// Without this the pre-imported package list can contain the package as we delete the .dll before we call 'AssetDatabase.Refresh()'.
if (UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false))
if (!isSlimRestore && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false))
{
Debug.LogWarning($"Uninstalling {package} makes no sense because it is a package that is 'pre-imported' by Unity.");
}
Expand All @@ -44,7 +45,7 @@ public static void Uninstall([NotNull] INugetPackageIdentifier package, PackageU
PackageContentManager.DeletePackageContentPackage(foundPackage);

// Since uninstall all will remove all packages we don't have to handle dependencies here.
if (uninstallReason != PackageUninstallReason.UninstallAll)
if (uninstallReason != PackageUninstallReason.UninstallAll && !isSlimRestore)
{
// uninstall all non manually installed dependencies that are not a dependency of another installed package
var frameworkDependencies = foundPackage.CurrentFrameworkDependencies;
Expand Down
8 changes: 5 additions & 3 deletions src/NuGetForUnity/Editor/NugetPackageUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static bool Update(
bool refreshAssets = true,
PackageUninstallReason uninstallReason = PackageUninstallReason.IndividualUpdate)
{
var result = UpdateWithInformation(currentVersion, newVersion, refreshAssets, uninstallReason);
var result = UpdateWithInformation(currentVersion, newVersion, refreshAssets, false, uninstallReason);
return result.Successful;
}

Expand Down Expand Up @@ -73,18 +73,20 @@ public static void UpdateAll(
/// <param name="currentVersion">The current package to uninstall.</param>
/// <param name="newVersion">The package to install.</param>
/// <param name="refreshAssets">True to refresh the assets inside Unity. False to ignore them (for now). Defaults to true.</param>
/// <param name="isSlimRestoreInstall">True if update needs to be done as part of slim restore operation.</param>
/// <param name="uninstallReason">The reason uninstall is being called.</param>
/// <returns>The information about how the package has been installed.</returns>
internal static PackageInstallOperationResult UpdateWithInformation(
[NotNull] INugetPackageIdentifier currentVersion,
[NotNull] INugetPackage newVersion,
bool refreshAssets = true,
bool isSlimRestoreInstall = false,
PackageUninstallReason uninstallReason = PackageUninstallReason.IndividualUpdate)
{
NugetLogger.LogVerbose("Updating {0} {1} to {2}", currentVersion.Id, currentVersion.Version, newVersion.Version);
NugetPackageUninstaller.Uninstall(currentVersion, uninstallReason, false);
NugetPackageUninstaller.Uninstall(currentVersion, uninstallReason, false, isSlimRestoreInstall);
newVersion.IsManuallyInstalled = newVersion.IsManuallyInstalled || currentVersion.IsManuallyInstalled;
return NugetPackageInstaller.Install(newVersion, refreshAssets);
return NugetPackageInstaller.Install(newVersion, refreshAssets, isSlimRestoreInstall);
}
}
}

0 comments on commit 54c6f94

Please sign in to comment.