Skip to content

Preserve Win32 resources in aggregate executable shims#128971

Open
Copilot wants to merge 5 commits into
mainfrom
copilot/restore-dumpnativeresources-task
Open

Preserve Win32 resources in aggregate executable shims#128971
Copilot wants to merge 5 commits into
mainfrom
copilot/restore-dumpnativeresources-task

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 4, 2026

Summary

Adds support for carrying managed assembly Win32 resources into NativeAOT aggregate executable shim binaries on Windows.

Changes

  • Adds DumpNativeResources to convert PE Win32 resources into .res files (restored from 4e48d2d that deleted it)
  • Links generated resource files into Windows aggregate executable shims.
  • Includes shim resource files in incremental build inputs.
  • Adds an aggregate executable test validating shim execution and resource preservation.
  • De-duplicates the Win32 resource test logic and test.res asset.

Validation

  • Shared Win32 resource sources compile successfully in temp projects.
  • Win32Resources.csproj builds successfully.
  • Targeted NativeAOT aggregate build is blocked by missing local ILCompiler targets in this fresh checkout, matching the pre-existing baseline failure.

Copilot AI and others added 5 commits June 4, 2026 04:30
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>
Copilot AI self-assigned this Jun 4, 2026
Copilot AI review requested due to automatic review settings June 4, 2026 05:09
Copilot AI review requested due to automatic review settings June 4, 2026 05:09
Copilot AI requested a review from MichalStrehovsky June 4, 2026 05:18
@MichalStrehovsky MichalStrehovsky changed the title Share Win32 resource test assets with HelloExe Preserve Win32 resources in aggregate executable shims Jun 4, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@MichalStrehovsky MichalStrehovsky marked this pull request as ready for review June 4, 2026 21:12
Copilot AI review requested due to automatic review settings June 4, 2026 21:12
@MichalStrehovsky
Copy link
Copy Markdown
Member

@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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 .res file.
  • Extends aggregate executable shim generation on Windows to generate/link the .res into 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.

Comment on lines +45 to +60
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);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants