-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
C#: Enforce C# 10 in .csproj
files
#86375
Conversation
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.
While it's possible to use a newer C# language version than the default one for the target framework, some language features may require new API only available in newer versions of the framework. Also, using a newer C# version with an older .NET version is not supported by Microsoft.
Because of this I'm hesitant to upgrade the C# version without changing the TFM. And if we're just setting <LangVersion>
to the default then it seems redundant since it's the same as not specifying it.
Maybe you can explain the motivation behind this change?
@@ -2,9 +2,7 @@ | |||
|
|||
<PropertyGroup> | |||
<TargetFramework>net6.0</TargetFramework> | |||
|
|||
<LangVersion>11</LangVersion> |
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 don't know why we had 11 here, I don't think the tests use any C# 11 features. cc @paulloz
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 do use raw string literals, but it shouldn't be hard to change if we want to. The syntax is just a tad cleaner.
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.
Oh, I love raw string literals. Since we use C# 11 features then this change is wrong. Unfortunately, because we don't run the tests in CI, the checks pass even though it would break the project.
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.
Could we enable the dotnet tests in CI?
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 shouldn't be too complicated. I'm not familiar with what our standards from actions / workflows are, but it's basically calling dotnet test
from the test folder.
There's other projects in the repo targeting dotnet standard 2.0 with the language set to C# 10, so this isn't treading new ground. For the 6.0 projects, it is admittedly redundant, but after the weird loophole situation the build system found itself in I wanted to make sure that the expected language was at least specified across all projects |
That's true and I haven't checked but it's likely that we're using features that requires the language version upgrade which justifies it.
Just to be clear, specifying the C# 10 language version would not have prevented the situation1 since the LangVer checks just don't exist2 in the SDK. I'm not opposed to being more explicit though, as long as other contributors feel the same way. So if that's the only reason for this change I'd wait to see other contributors opinions, as a result I'll move this to the 4.x milestone but let me know if I misunderstood. Footnotes
|
I like the idea of homogenizing our C# versions. It'd be nice if we could at least get down to a single explicit version for each target framework used. IDK exactly what requirements we have in our projects targeting |
Yeah, that's the main reason. I did end up realizing these changes wouldn't have an impact on the issue after setting up the PR, but the intent of safeguarding ourselves through explicit declaration remains
Understanding why those projects are targeting |
The only projects that target
As for
|
Yes, I was more curious about the For all our As for internal test projects, I'd usually force the latest available version (not including |
Decided to try upgrading the listed projects in a separate PR, and they all seem to work fine still? They're building without a hitch at least |
876be52
to
b584c1e
Compare
|
Makes C#10 the language version explicitly in all
.scproj
files that didn't do so previously. The only exceptions are the projects still targetingv4.7.2
, as they'd need an overall update