diff --git a/tests/Microsoft.DotNet.Docker.Tests/Microsoft.DotNet.Docker.Tests.csproj b/tests/Microsoft.DotNet.Docker.Tests/Microsoft.DotNet.Docker.Tests.csproj
index e72fcffb52..cbe6c0229b 100644
--- a/tests/Microsoft.DotNet.Docker.Tests/Microsoft.DotNet.Docker.Tests.csproj
+++ b/tests/Microsoft.DotNet.Docker.Tests/Microsoft.DotNet.Docker.Tests.csproj
@@ -15,7 +15,6 @@
-
diff --git a/tests/Microsoft.DotNet.Docker.Tests/PowerShellTests.cs b/tests/Microsoft.DotNet.Docker.Tests/PowerShellTests.cs
index 9564c9a3ba..d125daa3f6 100644
--- a/tests/Microsoft.DotNet.Docker.Tests/PowerShellTests.cs
+++ b/tests/Microsoft.DotNet.Docker.Tests/PowerShellTests.cs
@@ -15,8 +15,6 @@
using System.Threading.Tasks;
using Polly;
using Polly.Retry;
-using SharpCompress.Common;
-using SharpCompress.Readers;
using Xunit;
using Xunit.Abstractions;
diff --git a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs
index 9fb098b44f..3cb61d9932 100644
--- a/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs
+++ b/tests/Microsoft.DotNet.Docker.Tests/SdkImageTests.cs
@@ -14,8 +14,8 @@
using System.Threading.Tasks;
using Polly;
using Polly.Retry;
-using SharpCompress.Common;
-using SharpCompress.Readers;
+using System.Formats.Tar;
+using System.IO.Compression;
using Xunit;
using Xunit.Abstractions;
@@ -280,23 +280,6 @@ private IEnumerable GetActualSdkContents(ProductImageData im
.OrderBy(fileInfo => fileInfo.Path);
}
- private static IEnumerable EnumerateArchiveContents(string path)
- {
- using FileStream fileStream = File.OpenRead(path);
- using IReader reader = ReaderFactory.Open(fileStream);
- using TempFolderContext tempFolderContext = FileHelper.UseTempFolder();
- reader.WriteAllToDirectory(tempFolderContext.Path, new ExtractionOptions() { ExtractFullPath = true });
-
- foreach (FileInfo file in new DirectoryInfo(tempFolderContext.Path).EnumerateFiles("*", SearchOption.AllDirectories))
- {
- using SHA512 sha512 = SHA512.Create();
- byte[] sha512HashBytes = sha512.ComputeHash(File.ReadAllBytes(file.FullName));
- string sha512Hash = BitConverter.ToString(sha512HashBytes).Replace("-", string.Empty);
- yield return new SdkContentFileInfo(
- file.FullName.Substring(tempFolderContext.Path.Length), sha512Hash);
- }
- }
-
private async Task> GetExpectedSdkContentsAsync(ProductImageData imageData)
{
string sdkUrl = GetSdkUrl(imageData);
@@ -312,7 +295,31 @@ await s_sdkDownloadPipeline.ExecuteAsync(async cancellationToken =>
await s_httpClient.DownloadFileAsync(new Uri(sdkUrl), sdkFile);
});
- files = EnumerateArchiveContents(sdkFile)
+ using TempFolderContext extractFolder = FileHelper.UseTempFolder();
+
+ if (Path.GetExtension(sdkUrl).Equals(".zip", StringComparison.OrdinalIgnoreCase))
+ {
+ ZipFile.ExtractToDirectory(sdkFile, extractFolder.Path);
+ }
+ else
+ {
+ using FileStream fileStream = File.OpenRead(sdkFile);
+ using var gzipStream = new GZipStream(fileStream, CompressionMode.Decompress);
+ TarFile.ExtractToDirectory(gzipStream, extractFolder.Path, overwriteFiles: false);
+ }
+
+ files = Directory.EnumerateFiles(extractFolder.Path, "*", SearchOption.AllDirectories)
+ .Select(file =>
+ {
+ string filePath = Path.GetFullPath(file);
+ string relativePath = Path.GetRelativePath(extractFolder.Path, filePath);
+
+ byte[] fileData = File.ReadAllBytes(filePath);
+ byte[] sha512HashBytes = SHA512.HashData(fileData);
+ string sha512Hash = Convert.ToHexString(sha512HashBytes);
+
+ return new SdkContentFileInfo(relativePath, sha512Hash);
+ })
.OrderBy(file => file.Path)
.ToArray();