Preserve Win32 resources in aggregate executable shims#128971
Conversation
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
|
@eduardo-vp could you please have a look at this addition to aggregate executables? This is so that we copy the Win32 resource (version, icon, etc.) from the executable to the shim. The Win32 resource extraction is something we've been shipping for years (it's restored from when it was deleted in 4e48d2d) so it doesn't need too much scrutiny. Copilot changed a couple lines though. |
There was a problem hiding this comment.
Pull request overview
This PR adds a Windows NativeAOT build step to preserve Win32 resources from managed assemblies when producing aggregate executable shim binaries, and wires a NativeAOT aggregate test executable to validate resource availability at runtime.
Changes:
- Introduces an MSBuild task (
DumpNativeResources) that converts a PE’s Win32 resource directory into a.resfile. - Extends aggregate executable shim generation on Windows to generate/link the
.resinto each shim and include it in incremental build inputs. - Reuses the existing Win32 resource smoke-test logic in the aggregate executable test (
HelloExe) to validate the shim’s resources.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/tests/nativeaot/SmokeTests/Win32Resources/Win32Resources.cs | Refactors the Win32 resource validation code into a reusable helper (ValidateWin32Resources) and makes Main optional via a define. |
| src/tests/nativeaot/AggregateExecutableLibrary/HelloExe/HelloExe.csproj | Adds Win32 resource embedding on Windows and links the shared Win32 validation source into the project. |
| src/tests/nativeaot/AggregateExecutableLibrary/HelloExe/HelloExe.cs | Invokes Win32 resource validation at runtime on Windows before printing output. |
| src/coreclr/tools/aot/ILCompiler.Build.Tasks/DumpNativeResources.cs | Adds the new build task to dump a PE’s Win32 resources into a .res file. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets | Generates .res files for aggregate shims, links them into the shim binaries, and adds them as incremental build inputs. |
| src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets | Adds ShimResourceFile metadata to aggregate executable reference items. |
| DirectoryEntry resourceDirectory = peFile.PEHeaders.PEHeader.ResourceTableDirectory; | ||
| if (resourceDirectory.Size != 0 | ||
| && peFile.PEHeaders.TryGetDirectoryOffset(resourceDirectory, out int rsrcOffset)) | ||
| { | ||
| using (var bw = new BinaryWriter(File.Create(ResourceFile))) | ||
| { | ||
| ResWriter.WriteResources(peFile, rsrcOffset, resourceDirectory.Size, bw); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| using (var bw = new BinaryWriter(File.Create(ResourceFile))) | ||
| { | ||
| ResWriter.WriteEmptyResourceFile(bw); | ||
| } | ||
| } |
Summary
Adds support for carrying managed assembly Win32 resources into NativeAOT aggregate executable shim binaries on Windows.
Changes
DumpNativeResourcesto convert PE Win32 resources into.resfiles (restored from 4e48d2d that deleted it)test.resasset.Validation
Win32Resources.csprojbuilds successfully.