Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
7 changes: 5 additions & 2 deletions src/NuGetForUnity/Editor/NugetPackageInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ private static bool Install([NotNull] INugetPackage package, bool refreshAssets,
// 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<string, List<ZipArchiveEntry>>();
var csFiles = new Dictionary<string, List<ZipArchiveEntry>>();
var anyFiles = new Dictionary<string, List<ZipArchiveEntry>>();
Expand All @@ -179,7 +183,7 @@ private static bool Install([NotNull] INugetPackage package, bool refreshAssets,
continue;
}

if (PackageContentManager.ShouldSkipUnpackingOnPath(entryFullName))
if (PackageContentManager.ShouldSkipUnpackingOnPath(entryFullName, hasContentFilesFolder))
{
continue;
}
Expand All @@ -206,7 +210,6 @@ private static bool Install([NotNull] INugetPackage package, bool refreshAssets,

// 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:
Expand Down
12 changes: 11 additions & 1 deletion src/NuGetForUnity/Editor/PackageContentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,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.
/// </param>
/// <param name="hasContentFilesFolder">
/// 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.
/// </param>
/// <returns>True if the file can be skipped, is not needed.</returns>
internal static bool ShouldSkipUnpackingOnPath([NotNull] string path)
internal static bool ShouldSkipUnpackingOnPath([NotNull] string path, bool hasContentFilesFolder)
{
if (path.EndsWith("/"))
{
Expand All @@ -120,6 +124,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/"))
{
Expand Down