-
Notifications
You must be signed in to change notification settings - Fork 205
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
Platform detection: Handle .NET 6 #1528
Conversation
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
🤖 GitHub commentsTo re-run your PR in the CI, just comment with:
|
Should there be tests for .NET 6 in this PR too? |
Update: done. @russcam this is ready for review. |
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've had another look, and made some further suggestions
@@ -12,7 +12,9 @@ public sealed class NetCoreAndNet5Fact : FactAttribute | |||
{ | |||
public NetCoreAndNet5Fact() |
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 think we should update the name to NetCoreAndNetFact
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.
Done.
RuntimeInformation.FrameworkDescription.StartsWith(DotNet5Prefix, StringComparison.OrdinalIgnoreCase); | ||
internal static readonly bool IsDotNet5OrNewer = | ||
RuntimeInformation.FrameworkDescription.StartsWith(DotNetPrefix, StringComparison.OrdinalIgnoreCase) && | ||
!RuntimeInformation.FrameworkDescription.StartsWith(DotNetFullFrameworkDescriptionPrefix, StringComparison.OrdinalIgnoreCase) && |
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.
Would it be sufficient to check
- the
FrameworkDescription
is at least 6 characters in length - starts with
.NET
- the sixth character is a digit?
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.
Yes, that'd also make it. I changed it.
@@ -13,7 +13,7 @@ namespace Elastic.Apm.Helpers | |||
{ | |||
internal static class PlatformDetection | |||
{ | |||
internal const string DotNet5Prefix = ".NET 5"; | |||
internal const string DotNetPrefix = ".NET "; |
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.
is the space at the end intended?
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.
Yes, we use this as a prefix and we always look for .NET [Version]
.
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.
It looks like PlatformDetection
could use the constants defined in Runtime
?
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.
Yes, that's a good point - done.
Regarding On the other hand I agree |
internal static readonly bool IsDotNet = | ||
RuntimeInformation.FrameworkDescription.StartsWith(DotNetPrefix, StringComparison.OrdinalIgnoreCase) && | ||
RuntimeInformation.FrameworkDescription.Length >= 6 | ||
&& int.TryParse(RuntimeInformation.FrameworkDescription.Substring(5).Split('.')[0], out _); |
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.
&& int.TryParse(RuntimeInformation.FrameworkDescription.Substring(5).Split('.')[0], out _); | |
&& char.IsDigit(RuntimeInformation.FrameworkDescription[5]); |
char.IsDigit
?
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.
The thinking behind handling this as multiple characters was .NET 10 and newer (yeah, I know... it's a long time until then).
It'd still work if everything is fine by just checking the 1. character and ignoring the 2. This runs only once, so I think overhead should not matter here.
Anyways, I changed it to use char.IsDigit
.
@@ -13,7 +13,7 @@ namespace Elastic.Apm.Helpers | |||
{ | |||
internal static class PlatformDetection | |||
{ | |||
internal const string DotNet5Prefix = ".NET 5"; | |||
internal const string DotNetPrefix = ".NET "; |
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.
It looks like PlatformDetection
could use the constants defined in Runtime
?
Closes #1513