diff --git a/src/NuGetForUnity/Editor/NugetPackageInstaller.cs b/src/NuGetForUnity/Editor/NugetPackageInstaller.cs index 41756a91..3bd8c72e 100644 --- a/src/NuGetForUnity/Editor/NugetPackageInstaller.cs +++ b/src/NuGetForUnity/Editor/NugetPackageInstaller.cs @@ -188,6 +188,10 @@ private static bool Install( // unzip the package using (var zip = ZipFile.OpenRead(cachedPackagePath)) { + // check if nuget package has contentFiles folder + const string contentFilesDirectoryName = "contentFiles/"; + var hasContentFilesFolder = zip.Entries.Any(entry => entry.FullName.StartsWith(contentFilesDirectoryName, StringComparison.Ordinal)); + var libs = new Dictionary>(); var csFiles = new Dictionary>(); var anyFiles = new Dictionary>(); @@ -201,7 +205,7 @@ private static bool Install( continue; } - if (PackageContentManager.ShouldSkipUnpackingOnPath(entryFullName)) + if (PackageContentManager.ShouldSkipUnpackingOnPath(entryFullName, hasContentFilesFolder)) { continue; } @@ -228,7 +232,6 @@ private static bool Install( // in case this is a source code package, we want to collect all its entries that have 'cs' or 'any' set as language // and their frameworks so we can get the best framework later - const string contentFilesDirectoryName = "contentFiles/"; if (entryFullName.StartsWith(contentFilesDirectoryName, StringComparison.Ordinal)) { // Folder structure for source code packages: diff --git a/src/NuGetForUnity/Editor/PackageContentManager.cs b/src/NuGetForUnity/Editor/PackageContentManager.cs index 1bff86c9..be884ea4 100644 --- a/src/NuGetForUnity/Editor/PackageContentManager.cs +++ b/src/NuGetForUnity/Editor/PackageContentManager.cs @@ -110,8 +110,12 @@ internal static void CleanInstallationDirectory([NotNull] INugetPackageIdentifie /// The path of the file inside the .nupkg it is relative starting from the package route. It always uses '/' as a slash on all /// platforms. /// + /// + /// The package has contentfiles folder, we need to omit content folder it exist. Because some nuget package has both folder to + /// to support old version and new version of nuget. + /// /// True if the file can be skipped, is not needed. - internal static bool ShouldSkipUnpackingOnPath([NotNull] string path) + internal static bool ShouldSkipUnpackingOnPath([NotNull] string path, bool hasContentFilesFolder) { if (path.EndsWith("/")) { @@ -121,6 +125,12 @@ internal static bool ShouldSkipUnpackingOnPath([NotNull] string path) return true; } + // skip content folder when it has contentFiles folder + if (hasContentFilesFolder && (path.StartsWith("content/", StringComparison.Ordinal) || path.Contains("/content/"))) + { + return true; + } + // skip directories & files that NuGet normally deletes if (path.StartsWith("_rels/", StringComparison.Ordinal) || path.Contains("/_rels/")) {