Skip to content

[nativeaot] fix .resx files in apps #9905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 12, 2025
Merged

Conversation

jonathanpeppers
Copy link
Member

The EmbeddedResources_ShouldBeLocalized() test was failing under a NativeAOT context:

Embedded string resource did not contain expected value after changing CultureInfo.
String lengths are both 1. Strings differ at index 0.
Expected: "b"
But was:  "a"
-----------^

After reviewing a .binlog, it appears the _ComputeIlcCompileInputs MSBuild target was not working as expected:

https://github.com/dotnet/runtime/blob/cc803458ab4dabf020b462873be5bf56f1640b1e/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets#L3-L11

@(IntermediateSatelliteAssembliesWithTargetPath) was blank!

The problem being the way Android has an "inner" build per RID:

  • @(IntermediateSatelliteAssembliesWithTargetPath) is set in the "outer" build.

  • @(IntermediateSatelliteAssembliesWithTargetPath) is blank in the "inner" build per RID.

  • The "inner" build is where the ILC compiler runs, and so it doesn't see the current project's *.resource.dll file.

To fix this, we can pass $(_OuterIntermediateSatelliteAssembliesWithTargetPath) into the inner build.

I updated an MSBuild test to run normally and in a NativeAOT context.

The `EmbeddedResources_ShouldBeLocalized()` test was failing under a
NativeAOT context:

    Embedded string resource did not contain expected value after changing CultureInfo.
    String lengths are both 1. Strings differ at index 0.
    Expected: "b"
    But was:  "a"
    -----------^

After reviewing a `.binlog`, it appears the `_ComputeIlcCompileInputs`
MSBuild target was not working as expected:

https://github.com/dotnet/runtime/blob/cc803458ab4dabf020b462873be5bf56f1640b1e/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets#L3-L11

`@(IntermediateSatelliteAssembliesWithTargetPath)` was blank!

The problem being the way Android has an "inner" build per RID:

* `@(IntermediateSatelliteAssembliesWithTargetPath)` is set in the
  "outer" build.

* `@(IntermediateSatelliteAssembliesWithTargetPath)` is blank in the
  "inner" build per RID.

* The "inner" build is where the ILC compiler runs, and so it doesn't
  see the current project's `*.resource.dll` file.

To fix this, we can pass `$(_OuterIntermediateSatelliteAssembliesWithTargetPath)`
into the inner build.

I updated an MSBuild test to run normally and in a NativeAOT context.
@jonpryor jonpryor merged commit 43f82b7 into main Mar 12, 2025
58 checks passed
@jonpryor jonpryor deleted the dev/peppers/nativeaotresx branch March 12, 2025 12:30
IsRelease = value;
// Only toggle IsRelease=true when value is true
if (value)
IsRelease = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

If I want to say unit test a NativeAOT app in debug mode is this going to stop that from working?

Copy link
Member Author

@jonathanpeppers jonathanpeppers Mar 12, 2025

Choose a reason for hiding this comment

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

I would maybe still test Release configuration and set $(DebugType) and $(DebugSymbols).

Eventually, I think $(PublishAot)=true in Debug mode will still use Mono (or CoreCLR), so our managed debuggers will work.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants