Skip to content

[tests] remove runtimeconfig.template.json in favor of @(RuntimeHostConfigurationOption) #9890

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 1 commit into from
Mar 7, 2025

Conversation

jonathanpeppers
Copy link
Member

NativeAOT doesn't support runtimeconfig.template.json and it emits the build warning:

D:\.nuget\packages\microsoft.dotnet.ilcompiler\10.0.0-preview.3.25152.2\build\Microsoft.NETCore.Native.Publish.targets(46,5):
The published project has a runtimeconfig.template.json that is not supported by PublishAot. Move the configuration to the project file using RuntimeHostConfigurationOption.

So, instead of using runtimeconfig.template.json with contents:

{
    "configProperties": {
        "test_bool": true,
        "test_integer": 42,
        "test_string": "foo"
    }
}

You can simply define them in your .csproj as:

<ItemGroup>
  <RuntimeHostConfigurationOption Include="test_bool"    Value="true" />
  <RuntimeHostConfigurationOption Include="test_integer" Value="42" />
  <RuntimeHostConfigurationOption Include="test_string"  Value="foo" />
</ItemGroup>

Honestly, I think I prefer the MSBuild item group.

We don't necessarily care how the values are defined, just that these values at build time are set at runtime, and we can assert them in AppContextTests.cs.

…stConfigurationOption)`

NativeAOT doesn't support `runtimeconfig.template.json` and it emits
the build warning:

    D:\.nuget\packages\microsoft.dotnet.ilcompiler\10.0.0-preview.3.25152.2\build\Microsoft.NETCore.Native.Publish.targets(46,5):
    The published project has a runtimeconfig.template.json that is not supported by PublishAot. Move the configuration to the project file using RuntimeHostConfigurationOption.

So, instead of using `runtimeconfig.template.json` with contents:

    {
        "configProperties": {
            "test_bool": true,
            "test_integer": 42,
            "test_string": "foo"
        }
    }

You can simply define them in your `.csproj` as:

    <ItemGroup>
      <RuntimeHostConfigurationOption Include="test_bool"    Value="true" />
      <RuntimeHostConfigurationOption Include="test_integer" Value="42" />
      <RuntimeHostConfigurationOption Include="test_string"  Value="foo" />
    </ItemGroup>

Honestly, I think I prefer the MSBuild item group.

We don't necessarily care how the values are defined, just that these
values at build time are set at runtime, and we can assert them in
`AppContextTests.cs`.
@jonpryor jonpryor merged commit 1d099e7 into main Mar 7, 2025
58 checks passed
@jonpryor jonpryor deleted the dev/peppers/runtimeconfig.template.json branch March 7, 2025 19:10
@github-actions github-actions bot locked and limited conversation to collaborators Apr 7, 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.

2 participants