Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed restore from CLI when packages need to be updated #694

Merged
merged 2 commits into from
Feb 1, 2025
Merged
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
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)
igor84 marked this conversation as resolved.
Show resolved Hide resolved
{
// 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,
igor84 marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
}
Loading