Conversation
For .NET 8 and .NET 10
There was a problem hiding this comment.
Pull request overview
This PR marks the SharpCompress library as AOT (Ahead-of-Time) compatible by adding the <IsAotCompatible>true</IsAotCompatible> property to the project file for .NET 8.0 and .NET 10.0 target frameworks. The author tested with standard build, pack, and test commands on Ubuntu 24.04 with .NET 10.
Changes:
- Added
IsAotCompatibleproperty to the project configuration for .NET 8.0 and .NET 10.0 frameworks
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(TargetFramework)' == 'net8.0' Or '$(TargetFramework)' == 'net10.0' "> | ||
| <IsTrimmable>true</IsTrimmable> | ||
| <IsAotCompatible>true</IsAotCompatible> |
There was a problem hiding this comment.
The library contains patterns that are problematic for Native AOT compilation. Specifically, in src/SharpCompress/Common/Zip/ZipEntry.cs line 27, the code uses header.GetType() == typeof(UnixTimeExtraField) for runtime type checking. This pattern is not AOT-friendly.
Other parts of the codebase use the proper pattern: u.Type == ExtraDataType.UnixTimeExtraField (see DirectoryEntryHeader.cs:93 and LocalEntryHeader.cs:72). The ZipEntry.cs code should be refactored to match this approach by using the Type property instead of GetType().
Additionally, the library uses Enum.IsDefined in several locations (TarArchive.Factory.cs, ZipArchive.Factory.cs, ArjHeader.cs, ZipFileEntry.cs). While Enum.IsDefined with typeof() is technically supported in .NET 8+ AOT, it does generate AOT analysis warnings in some scenarios.
Before marking this library as AOT compatible, these patterns should be addressed, and the library should be tested with PublishAot=true to ensure no AOT warnings are generated during compilation.
| <IsAotCompatible>true</IsAotCompatible> | |
| <IsAotCompatible>false</IsAotCompatible> |
|
Added to release, hope it works |
|
in master too |
For .NET 8 and .NET 10
I tested with
dotnet buildanddotnet packfrom src folder. Also I randotnet testwithout issues. Tested with Ubuntu 24.04 + .NET 10 under WSL.