diff --git a/src/NuGetForUnity.Tests/Assets/Tests/Resources/NuGet.config b/src/NuGetForUnity.Tests/Assets/Tests/Resources/NuGet.config index 97f21355..8362190c 100644 --- a/src/NuGetForUnity.Tests/Assets/Tests/Resources/NuGet.config +++ b/src/NuGetForUnity.Tests/Assets/Tests/Resources/NuGet.config @@ -15,9 +15,10 @@ + - + \ No newline at end of file diff --git a/src/NuGetForUnity/Editor/NugetPackageInstaller.cs b/src/NuGetForUnity/Editor/NugetPackageInstaller.cs index 9fd20529..41756a91 100644 --- a/src/NuGetForUnity/Editor/NugetPackageInstaller.cs +++ b/src/NuGetForUnity/Editor/NugetPackageInstaller.cs @@ -24,8 +24,13 @@ public static class NugetPackageInstaller /// The identifier of the package to install. /// True to refresh the Unity asset database. False to ignore the changes (temporarily). /// True to skip checking if lib is imported in Unity and skip installing dependencies. + /// False to prevent updating of packages that are explicitly installed. /// True if the package was installed successfully, otherwise false. - public static bool InstallIdentifier([NotNull] INugetPackageIdentifier package, bool refreshAssets = true, bool isSlimRestoreInstall = false) + public static bool InstallIdentifier( + [NotNull] INugetPackageIdentifier package, + bool refreshAssets = true, + bool isSlimRestoreInstall = false, + bool allowUpdateForExplicitlyInstalled = true) { if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false)) { @@ -42,7 +47,7 @@ public static bool InstallIdentifier([NotNull] INugetPackageIdentifier package, } foundPackage.IsManuallyInstalled = package.IsManuallyInstalled; - return Install(foundPackage, refreshAssets, isSlimRestoreInstall); + return Install(foundPackage, refreshAssets, isSlimRestoreInstall, allowUpdateForExplicitlyInstalled); } /// @@ -51,8 +56,13 @@ public static bool InstallIdentifier([NotNull] INugetPackageIdentifier package, /// The package to install. /// True to refresh the Unity asset database. False to ignore the changes (temporarily). /// True to skip checking if lib is imported in Unity and skip installing dependencies. + /// False to prevent updating of packages that are explicitly installed. /// True if the package was installed successfully, otherwise false. - private static bool Install([NotNull] INugetPackage package, bool refreshAssets, bool isSlimRestoreInstall) + private static bool Install( + [NotNull] INugetPackage package, + bool refreshAssets, + bool isSlimRestoreInstall, + bool allowUpdateForExplicitlyInstalled) { if (!isSlimRestoreInstall && UnityPreImportedLibraryResolver.IsAlreadyImportedInEngine(package.Id, false)) { @@ -64,6 +74,18 @@ private static bool Install([NotNull] INugetPackage package, bool refreshAssets, if (InstalledPackagesManager.TryGetById(package.Id, out var installedPackage)) { var comparisonResult = installedPackage.CompareTo(package); + + if (!allowUpdateForExplicitlyInstalled && comparisonResult != 0 && installedPackage.IsManuallyInstalled) + { + NugetLogger.LogVerbose( + "{0} {1} is installed explicitly so it will not be replaced with {3}", + installedPackage.Id, + installedPackage.Version, + package.Version, + package.Version); + return true; + } + if (comparisonResult < 0) { NugetLogger.LogVerbose( @@ -131,7 +153,7 @@ private static bool Install([NotNull] INugetPackage package, bool refreshAssets, foreach (var dependency in frameworkGroup.Dependencies) { NugetLogger.LogVerbose("Installing Dependency: {0} {1}", dependency.Id, dependency.Version); - var installed = InstallIdentifier(dependency, false); + var installed = InstallIdentifier(dependency, false, false, false); if (!installed) { throw new InvalidOperationException($"Failed to install dependency: {dependency.Id} {dependency.Version}.");