Benchmarks icon indicating copy to clipboard operation
Benchmarks copied to clipboard

Update dependencies and clean up some warnings for net11.0 support

Open LoopedBard3 opened this issue 1 month ago • 5 comments

Update dependencies and clean up leftover warnings when building Benchmarks.csproj. This adds support for net11.0 when building the Benchmarks.csproj project with a clean build. This should also fix failing tech-empower testing in the optimization repo (or at least get us further along in the test).

The decently sized Program.cs change is really just taking the previous code and putting it inside of the ConfigureWebHost function.

When building net11, the warnings that were cleaned up were:

dotnet build -c Release -f net11.0 /p:TargetFramework=net11.0
    info NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  Benchmarks net11.0 succeeded with 4 warning(s) (26.3s) → bin\Release\net11.0\Benchmarks.dll
    C:\Users\<user>\repos\benchmarks\src\Benchmarks\Program.cs(58,38): warning ASPDEPR004: 'WebHostBuilder' is obsolete: 'WebHostBuilder is deprecated in favor of HostBuilder and WebApplicationBuilder. For more information, visit https://aka.ms/aspnet/deprecate/004.' (https://aka.ms/aspnet/deprecate/004)
    C:\Users\<user>\repos\benchmarks\src\Benchmarks\Program.cs(151,27): warning ASPDEPR008: 'IWebHostBuilder.Build()' is obsolete: 'IWebHost is obsolete. Use IHost instead. For more information, visit https://aka.ms/aspnet/deprecate/008.' (https://aka.ms/aspnet/deprecate/008)
    C:\Users\<user>\repos\benchmarks\src\Benchmarks\Data\World.cs(13,10): warning DAP043: Attach the [UseColumnAttribute] attribute to make Dapper consider [Column] (https://aot.dapperlib.dev/rules/DAP043)
    C:\Users\<user>\repos\benchmarks\src\Benchmarks\Data\World.cs(20,10): warning DAP043: Attach the [UseColumnAttribute] attribute to make Dapper consider [Column] (https://aot.dapperlib.dev/rules/DAP043)

Build succeeded with 4 warning(s) in 26.7s

I tested building this with the latest net11 alpha locally and it built successfully. What other testing should be done before merging this?

LoopedBard3 avatar Dec 16 '25 18:12 LoopedBard3

Looks good, please try to run a Benchmark though that triggers the Benchmarks.csproj app (Json middleware a.k.a Json) on net8, 10 and 11. 11 might fail because of crank support.

sebastienros avatar Dec 16 '25 19:12 sebastienros

Cool, I will run those tests now that I have a version of the app that is building and running locally (took a few iterations to get past the System.InvalidOperationException: Unable to resolve service for type... error and ensure the final warnings could be suppressed. The set of changes for this was mostly to move from trying to Inject Scenarios into Startup, which is not available with the new classes, to instead getting and setting Scenarios in ConfigureServices and moving the UseStartup to after ConfigureServices as the StartupService depends on the Scenarios Singleton. The high-level changes that require this is HostBuilder limiting Startups potential DI candidates to IConfiguration, IHostEnvironment and IWebHostEnvironment. More Info.

With this in mind, if anyone has ideas for other or preferred approaches they would be greatly appreciated. I can also not make those changes in this PR and can make another PR to deal with the deprecation warnings.

LoopedBard3 avatar Dec 16 '25 22:12 LoopedBard3

The new HostBuilder does not output Application Started... by default, so the latest update moves from using Run() to using Start(), manually printing the message, and then WaitForShutdown(). I have tested this version in the dotnet-optimization flow and it ran successfully AFAICT: opt run

Still need to test for net8.0 and net10.0 via crank.

LoopedBard3 avatar Dec 17 '25 20:12 LoopedBard3

https://github.com/aspnet/Benchmarks/blob/main/src/BenchmarksApps/TechEmpower/Minimal/Program.cs#L52

sebastienros avatar Dec 17 '25 20:12 sebastienros

For now, to get the update in to fix optimization runs, I am going to save the Startup.cs and Program.cs updates for PR. The initial switch I did used HostBuilder which does not provide the same Lifetime tie-ins and the app should be updated to use the WebApplication approach (ASP.NET Core 6+) which seems like it will be a larger update (especially as I am not well-versed with ASP.NET Core apps). Basically ASP.NET Core 2.x -> ASP.NET Core 6 will be a bigger jump than I want to have for this PR.

As such, the following warnings will show up:

<path>/artifacts/out/DotNet_TechEmpower/aspnet-benchmarks/src/Benchmarks/Program.cs(58,38): warning ASPDEPR004: 'WebHostBuilder' is obsolete: 'WebHostBuilder is deprecated in favor of HostBuilder and WebApplicationBuilder. For more information, visit https://aka.ms/aspnet/deprecate/004.' (https://aka.ms/aspnet/deprecate/004) [<path>/artifacts/out/DotNet_TechEmpower/aspnet-benchmarks/src/Benchmarks/Benchmarks.csproj]
<path>/artifacts/out/DotNet_TechEmpower/aspnet-benchmarks/src/Benchmarks/Program.cs(151,27): warning ASPDEPR008: 'IWebHostBuilder.Build()' is obsolete: 'IWebHost is obsolete. Use IHost instead. For more information, visit https://aka.ms/aspnet/deprecate/008.' (https://aka.ms/aspnet/deprecate/008) [<path>/artifacts/out/DotNet_TechEmpower/aspnet-benchmarks/src/Benchmarks/Benchmarks.csproj]
<path>/artifacts/out/DotNet_TechEmpower/aspnet-benchmarks/src/Benchmarks/Data/World.cs(13,10): warning DAP043: Attach the [UseColumnAttribute] attribute to make Dapper consider [Column] (https://aot.dapperlib.dev/rules/DAP043) [<path>/artifacts/out/DotNet_TechEmpower/aspnet-benchmarks/src/Benchmarks/Benchmarks.csproj]
<path>/artifacts/out/DotNet_TechEmpower/aspnet-benchmarks/src/Benchmarks/Data/World.cs(20,10): warning DAP043: Attach the [UseColumnAttribute] attribute to make Dapper consider [Column] (https://aot.dapperlib.dev/rules/DAP043) [<path>/artifacts/out/DotNet_TechEmpower/aspnet-benchmarks/src/Benchmarks/Benchmarks.csproj]

but based on this test run, everything should be good: https://dev.azure.com/dnceng/internal/_build/results?buildId=2863123&view=logs&j=3052c9a4-5368-55af-482b-1070f1d635d5&t=56e27cfc-3548-5f31-e7e0-7d617b0462b7.

LoopedBard3 avatar Dec 17 '25 23:12 LoopedBard3