Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

Repiteo
Copy link
Contributor

@Repiteo Repiteo commented Dec 21, 2023

Makes C#10 the language version explicitly in all .scproj files that didn't do so previously. The only exceptions are the projects still targeting v4.7.2, as they'd need an overall update

@Repiteo Repiteo requested a review from a team as a code owner December 21, 2023 03:00
@AThousandShips AThousandShips added this to the 4.3 milestone Dec 21, 2023
Copy link
Member

@raulsntos raulsntos left a 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>
Copy link
Member

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

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

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.

@Repiteo
Copy link
Contributor Author

Repiteo commented Dec 22, 2023

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

@raulsntos
Copy link
Member

There's other projects in the repo targeting dotnet standard 2.0 with the language set to C# 10

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.

For the 6.0 projects, it is admittedly redundant, but after the weird loophole situation the build system found itself in

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

  1. Referring to https://github.com/godotengine/godot/issues/86374.

  2. Removed by https://github.com/dotnet/roslyn/pull/62339.

@raulsntos raulsntos modified the milestones: 4.3, 4.x Dec 22, 2023
@paulloz
Copy link
Member

paulloz commented Dec 22, 2023

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 netstandard2.0, but we shouldn't have issues for net6 and net472 (another topic would be, do we still need to target net472 for those).

@Repiteo
Copy link
Contributor Author

Repiteo commented Dec 22, 2023

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.

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

IDK exactly what requirements we have in our projects targeting netstandard2.0, but we shouldn't have issues for net6 and net472 (another topic would be, do we still need to target net472 for those).

Understanding why those projects are targeting netstandard2.0/net472 would be good to iron out as well. For the latter, I would assume they're largely legacy projects with niche usecases to not warrant high priority in bringing up

@raulsntos
Copy link
Member

The only projects that target net472 are:

  • GodotTools.IdeMessaging.CLI which is just a test project for the IDE integration, it could probably be upgraded but I think the IDE integration as a whole is kind of in need of a refactor so I've postponed it so far.
  • GodotTools.OpenVisualStudio which uses Windows-only packages and APIs and is used to open Visual Studio as part of the IDE integration. I'm not sure if it can be upgraded or if the packages we use still require .NET Framework but it seems like it makes sense for this project to stay on net472.

As for netstandard2.0, this is the only TFM supported by source generators and analyzers so most of the projects that target it do it because of this reason. Apart from this, the other projects that target netstandard2.0 are:

  • GodotTools.IdeMessaging. This is probably related to the projects mentioned above that target net472 so it probably just targets netstandard2.0 so it can be consumed by both .NET Core and .NET Framework projects.
  • GodotTools.BuildLogger. I'm not sure if we really need this project to target netstandard2.0 and maybe it can be upgraded to net6.0.

@paulloz
Copy link
Member

paulloz commented Dec 22, 2023

this is the only TFM supported by source generators and analyzers

Yes, I was more curious about the net472 ones.

For all our netstandard2.0 generators/analyzers projects, I can't think of any reason we couldn't default to 10. They basically aren't supposed to be used with anything targeting under net6.0.

As for internal test projects, I'd usually force the latest available version (not including preview). But that's a personal thing, not sure everyone would agree.

@Repiteo
Copy link
Contributor Author

Repiteo commented Dec 22, 2023

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

@raulsntos
Copy link
Member

@raulsntos raulsntos closed this May 21, 2024
@raulsntos raulsntos removed this from the 4.x milestone May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants