Skip to content

Commit 5cecce6

Browse files
Fix .NET 10 CompileTrimmingSamples
1 parent 25d1045 commit 5cecce6

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

tracer/build/_build/TargetFrameworkExtensions.cs

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
1-
public static class TargetFrameworkExtensions
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
public static class TargetFrameworkExtensions
25
{
6+
private static readonly string[] IgnoredFrameworks = { "net461", "net48", "netstandard2.0" };
7+
8+
private static readonly List<string> OrderedFrameworks = new()
9+
{
10+
"netcoreapp2.1",
11+
"netcoreapp3.0",
12+
"netcoreapp3.1",
13+
"net5.0",
14+
"net6.0",
15+
"net7.0",
16+
"net8.0",
17+
"net9.0",
18+
"net10.0"
19+
};
20+
321
/// <summary>
422
/// Is <paramref name="instance"/> greater than <paramref name="target"/>.
523
/// Only works for .NET Core TFMs
624
/// </summary>
725
public static bool IsGreaterThan(this TargetFramework instance, TargetFramework target)
8-
=> ((string) instance, (string) target) switch
9-
{
10-
// We ignore these, because they don't really count
11-
("net461" or "net48" or "netstandard2.0", _) => false,
12-
(_, "net461" or "net48" or "netstandard2.0") => false,
13-
// real checks
14-
("netcoreapp3.0" or "netcoreapp3.1" or "net5.0" or "net6.0" or "net7.0" or "net8.0" or "net9.0", "netcoreapp2.1") => true,
15-
("netcoreapp3.1" or "net5.0" or "net6.0" or "net7.0" or "net8.0" or "net9.0", "netcoreapp3.0") => true,
16-
("net5.0" or "net6.0" or "net7.0" or "net8.0" or "net9.0", "netcoreapp3.1") => true,
17-
("net6.0" or "net7.0" or "net8.0" or "net9.0", "net5.0") => true,
18-
("net7.0" or "net8.0" or "net9.0", "net6.0") => true,
19-
("net9.0" or "net8.0", "net7.0") => true,
20-
("net9.0", "net8.0") => true,
21-
_ => false,
22-
};
26+
{
27+
var source = (string)instance;
28+
var compareTo = (string)target;
29+
30+
if (IgnoredFrameworks.Contains(source) || IgnoredFrameworks.Contains(compareTo))
31+
return false;
32+
33+
int sourceIndex = OrderedFrameworks.IndexOf(source);
34+
int targetIndex = OrderedFrameworks.IndexOf(compareTo);
35+
36+
return sourceIndex > targetIndex;
37+
}
2338

2439
/// <summary>
2540
/// Is <paramref name="instance"/> greater than <paramref name="target"/>.

0 commit comments

Comments
 (0)