-
Notifications
You must be signed in to change notification settings - Fork 464
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
Fix broken tests when running Config Schema Generator on .NET 9 #6312
base: main
Are you sure you want to change the base?
Conversation
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'"> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" VersionOverride="9.0.0-rc.2.24473.5" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" VersionOverride="9.0.0-rc.2.24473.5" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" VersionOverride="9.0.0-rc.2.24473.5" /> | ||
</ItemGroup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there's a better way. I've tried updating versions.props
but that breaks other things, so I've made the changes local. This is needed because the listed packages reference 8.0.0 versions otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed now. You should be able to revert these changes because of the following:
Lines 76 to 79 in 2e60ee6
<PropertyGroup Condition="'$(TargetFramework)' == 'net9.0'"> | |
<!-- Runtime --> | |
<MicrosoftExtensionsHostingAbstractionsPackageVersion>9.0.0-rc.2.24473.5</MicrosoftExtensionsHostingAbstractionsPackageVersion> | |
<MicrosoftExtensionsHostingPackageVersion>9.0.0-rc.2.24473.5</MicrosoftExtensionsHostingPackageVersion> |
This will automatically reference the 9.0 hosting packages when targeting net9.0
.
Hello @bart-vmware, thanks for the contribution. This PR is currently set to target release/9.0-rc.1 which is no longer an active branch. Assuming you are okay with me re-targeting it against |
@joperezr It probably won't work with Can I update this PR to make it compatible with |
We are pretty locked down at this point for release/9.0 branch, so unfortunately wouldn't be able to take this into there. |
Given the above, I'm retargeting this to go against main as the rc.1 branch is frozen anyway. |
@@ -78,7 +78,7 @@ | |||
<Target Name="CalculateConfigurationSchemaGeneratorPath"> | |||
<MSBuild Projects="$(ConfigurationSchemaGeneratorProjectPath)" | |||
Targets="GetTargetPath" | |||
RemoveProperties="TargetFramework"> | |||
Properties="$(Properties);TargetFramework=$(DefaultTargetFramework)"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is right. (actually I'm pretty sure it is wrong). Can you explain why you are proposing this change? What doesn't work about the current code?
@@ -1,7 +1,7 @@ | |||
<Project Sdk="Microsoft.NET.Sdk"> | |||
|
|||
<PropertyGroup> | |||
<TargetFramework>$(DefaultTargetFramework)</TargetFramework> | |||
<TargetFrameworks>$(AllTargetFrameworks)</TargetFrameworks> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need to multi-target the generator. It should only need to target net8.0
.
private static void ReplaceNodeWithKeyCasingChange(JsonObject jsonObject, string key, JsonNode value) | ||
{ | ||
#if NET9_0_OR_GREATER |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eiriktsarpalis - is this the recommended way to respond to the breaking change? Do we have documentation guidance on the break?
I almost wonder if we should be checking the System.Text.Json major version number instead. Or doing some sort of "runtime capability test" - for example, execute a method that checks for the new behavior and set a bool
flag.
The situation that can break this is if you are targeting net8.0
, but somehow the 9.0
System.Text.Json nuget package gets pulled into the app (ex. through a transitive reference). In that situation, the #else
code will be compiled into the app, but the 9.0 STJ behavior will happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I fully understand what tests were broken by the particular change in STJ 9, but per the discussion in dotnet/runtime#108790 (comment) the pre-9 behaviour is undocumented, accidental behaviour that is inconsistent with how all other dictionary types work in the same context.
We've agreed to add a breaking change note in our documentation for completeness, but beyond that I don't think it's appropriate to introduce mitigations down the stack just so that the pre-9 behavior is preserved. Assuming there are failing tests that check against that behavior, then I would recommend just updating the tests.
(Sorry for the late response. We were busy locking down for .NET Aspire 9.0, which will be released next week.) |
@@ -61,7 +61,7 @@ private void GenerateLogCategories(JsonObject parent) | |||
{ | |||
var categoryNode = new JsonObject(); | |||
categoryNode["$ref"] = "#/definitions/logLevelThreshold"; | |||
propertiesNode[categories[i]] = categoryNode; | |||
ReplaceNodeWithKeyCasingChange(propertiesNode, categories[i], categoryNode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that this is code copied from the config binder generator, is it appropriate to be making changes locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part of the code isn't copied from the config binder generator. The part that is copied is inside the https://github.com/dotnet/aspire/tree/main/src/Tools/ConfigurationSchemaGenerator/RuntimeSource directory.
Description
Adapt the Config Schema Generator logic to deal with the breaking change in
System.Text.Json
, reported at dotnet/runtime#108790.More specifically, this PR fixes the
JsonNode
handling inside Config Schema Generator to work with .NET 9 RC2. The generator project and its test project now multi-target .NET 8 and 9. However, the consuming projects still execute the .NET 8 version during build.Before this PR, the generator and its tests only ran on .NET 8, which is why there were no test failures.
Checklist
<remarks />
and<code />
elements on your triple slash comments?/cc @eerhardt
Microsoft Reviewers: Open in CodeFlow