diff --git a/src/Cake.Core.Tests/Unit/IO/FileExtensionsTests.cs b/src/Cake.Core.Tests/Unit/IO/FileExtensionsTests.cs index 176c0aa200..4a0fc5f3f3 100644 --- a/src/Cake.Core.Tests/Unit/IO/FileExtensionsTests.cs +++ b/src/Cake.Core.Tests/Unit/IO/FileExtensionsTests.cs @@ -297,6 +297,21 @@ public void Should_Return_False_When_File_Is_Not_A_Valid_PE() // Then Assert.False(FileExtensions.IsClrAssembly(file)); } + + [Fact] + public void Should_Return_False_When_File_Is_MacOS_MachO_dylib() + { + // Given + var file = Substitute.For(); + + // When + file.Exists.Returns(true); + file.Path.Returns(new string("fullname.dylib")); + file.Length.Returns(_invalidPeBytes.Length); + + // Then + Assert.False(FileExtensions.IsClrAssembly(file)); + } } } } \ No newline at end of file diff --git a/src/Cake.Core/IO/FileExtensions.cs b/src/Cake.Core/IO/FileExtensions.cs index c504962157..f42df8b3df 100644 --- a/src/Cake.Core/IO/FileExtensions.cs +++ b/src/Cake.Core/IO/FileExtensions.cs @@ -116,6 +116,28 @@ public static bool IsClrAssembly(this IFile file) return false; } + // Is known extension? + switch (file.Path?.GetExtension().ToLowerInvariant()) + { + case ".dll": + case ".exe": + case ".sys": + case ".tsp": + case ".acm": + case ".ax": + case ".cpl": + case ".drv": + case ".efi": + case ".mui": + case ".ocx": + case ".scr": + case null: + break; + + default: + return false; + } + using (var fs = file.OpenRead()) { using (var reader = new System.IO.BinaryReader(fs))