dotnet / crank

Benchmarking infrastructure for applications
MIT License
975 stars 103 forks source link

TFM patching bug when multiple TargetFramework(s) tags with conditions are present #662

Open CarnaViire opened 9 months ago

CarnaViire commented 9 months ago

Microbenchmarks in Crank don't work for .NET 9.0 currently (logs):

Command:
dotnet publish MicroBenchmarks.csproj ....
....
error NETSDK1005: Assets file 'C:\Users\ .... \MicroBenchmarks\project.assets.json' doesn't have a target for 'net9.0'. Ensure that restore has run and that you have included 'net9.0' in the TargetFrameworks for your project.

The reason for that is a bug(?) when Crank is patching the TFM: it changes the first <TargetFrameworks> tag to just <TargetFramework> (without s) -- however, Microbenchmarks project file has some additional logic that depends on <TargetFrameworks> (with s) tag value being set (src):

    <!-- Used by Python script to narrow down the specified target frameworks to test, and avoid downloading all supported SDKs -->
    <TargetFrameworks>$(PERFLAB_TARGET_FRAMEWORKS)</TargetFrameworks>
    <!-- Supported target frameworks -->
    <TargetFrameworks Condition="'$(TargetFrameworks)' == '' AND '$(OS)' == 'Windows_NT'">net462;net6.0;net7.0;net8.0</TargetFrameworks>
    <TargetFrameworks Condition="'$(TargetFrameworks)' == '' AND '$(OS)' != 'Windows_NT'">net6.0;net7.0;net8.0</TargetFrameworks>

-- which results in <TargetFrameworks> being set by this logic, essentially overriding the TFM patch Crank did. This, by chance, was "working" for 8.0, because net8.0 was present in the resulted TFMs list, but it does not work for net9.0, which is not present there yet.

While Microbenchmarks could be updated to include 9.0 (I'm trying to do that in https://github.com/dotnet/performance/pull/3504), the problem with the patching itself might resurface again -- in other projects, or in Microbenchmarks for vNext.