Skip to content

[Xamarin.Android.Build.Tasks] fix C# 8.0 support by default#5054

Merged
jonpryor merged 1 commit intodotnet:masterfrom
jonathanpeppers:fix-csharp-8
Aug 28, 2020
Merged

[Xamarin.Android.Build.Tasks] fix C# 8.0 support by default#5054
jonpryor merged 1 commit intodotnet:masterfrom
jonathanpeppers:fix-csharp-8

Conversation

@jonathanpeppers
Copy link
Member

Fixes: #5049
Context: dotnet/roslyn@12f1b8f#diff-125e2d8c52dd9033f9b248f79f78c3f8
Context: dotnet/roslyn#44911 (comment)

The BuildTest.CSharp8Features test was failing for me locally where
I have Visual Studio 2019 16.7.2 installed:

Foo.cs(1,23): error CS8370: Feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater.

After review, it appears that a change in Roslyn's MSBuild targets
removed $(MaxSupportedLangVersion) and made the property private:
$(_MaxSupportedLangVersion).

After some discussion around C# 9.0:

  • It is unknown if C# 9.0 will be supported by mono/mono/2020-02. Some
    features like covariant return types and function pointers require
    runtime changes.
  • Using a build of .NET 5 rc1, $(LangVersion) is already being set
    to 9.0 by default.

We should just change the current behavior of:

<MaxSupportedLangVersion Condition=" '$(MaxSupportedLangVersion)' == '' ">8.0</MaxSupportedLangVersion>

And change it to:

<LangVersion Condition=" '$(LangVersion)' == '' ">8.0</LangVersion>

This matches what Roslyn's default behavior is:

https://github.com/dotnet/roslyn/blob/1aeda2e94fb9371b96d4bfd94b074860064ec3d2/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets#L6-L21

.NET 5+ projects should be unaffected by this change, as they do not
import Xamarin.Android.CSharp.targets.

If at some point, mono/mono/2020-02 fully supports C# we can bump this
value. Users can opt into 9.0 on their own if desired.

BuildTest.CSharp8Features now passes for me locally.

Fixes: dotnet#5049
Context: dotnet/roslyn@12f1b8f#diff-125e2d8c52dd9033f9b248f79f78c3f8
Context: dotnet/roslyn#44911 (comment)

The `BuildTest.CSharp8Features` test was failing for me locally where
I have Visual Studio 2019 16.7.2 installed:

    Foo.cs(1,23): error CS8370: Feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater.

After review, it appears that a change in Roslyn's MSBuild targets
removed `$(MaxSupportedLangVersion)` and made the property private:
`$(_MaxSupportedLangVersion)`.

After some discussion around C# 9.0:

* It is unknown if C# 9.0 will be supported by mono/mono/2020-02. Some
  features like covariant return types and function pointers require
  runtime changes.
* Using a build of .NET 5 rc1, `$(LangVersion)` is already being set
  to `9.0` by default.

We should just change the current behavior of:

    <MaxSupportedLangVersion Condition=" '$(MaxSupportedLangVersion)' == '' ">8.0</MaxSupportedLangVersion>

And change it to:

    <LangVersion Condition=" '$(LangVersion)' == '' ">8.0</LangVersion>

This matches what Roslyn's default behavior is:

https://github.com/dotnet/roslyn/blob/1aeda2e94fb9371b96d4bfd94b074860064ec3d2/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets#L6-L21

.NET 5+ projects should be unaffected by this change, as they do not
import `Xamarin.Android.CSharp.targets`.

If at some point, mono/mono/2020-02 fully supports C# we can bump this
value. Users can opt into `9.0` on their own if desired.

`BuildTest.CSharp8Features` now passes for me locally.
Comment on lines +1 to +5
#### Application and library build and deployment

* [GitHub Issue 5049](https://github.com/xamarin/xamarin-android/issues/5049):
*Feature 'XYZ' is not available in C# 7.3. Please use language version 8.0 or greater.*
build error could prevent projects from using C# 8.0 language features.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release note approved. Thanks!

In the final collated release notes, I'll plan to make one tiny addition to include the version where the behavior started. Feel free to comment back if anything looks bad about this adjustment though.

#### Application and library build and deployment

* [GitHub Issue 5049](https://github.com/xamarin/xamarin-android/issues/5049):
  Starting in Visual Studio 2019 version 16.7, build errors similar to *Feature
  'XYZ' is not available in C# 7.3. Please use language version 8.0 or greater.*
  could prevent projects from using C# 8.0 language features.

@jonpryor jonpryor merged commit 3d3f650 into dotnet:master Aug 28, 2020
jonpryor pushed a commit that referenced this pull request Aug 28, 2020
Fixes: #5049

Context: dotnet/roslyn@12f1b8f#diff-125e2d8c52dd9033f9b248f79f78c3f8
Context: dotnet/roslyn#44911 (comment)

The `BuildTest.CSharp8Features()` test was failing for me locally when
I have Visual Studio 2019 16.7.2 installed:

	Foo.cs(1,23): error CS8370: Feature 'using declarations' is not available in C# 7.3. Please use language version 8.0 or greater.

After review, it appears that a change in Roslyn's MSBuild targets
[removed `$(MaxSupportedLangVersion)`][0] and made the property\
private: `$(_MaxSupportedLangVersion)`.

After some discussion around C# 9.0:

  * It is unknown if C# 9.0 will be supported by mono/mono/2020-02.
    Some features like covariant return types and function pointers
    require runtime changes.

  * Using a build of .NET 5 rc1, `$(LangVersion)` is already being set
    to `9.0` by default.

We should just change the current behavior of:

	<MaxSupportedLangVersion Condition=" '$(MaxSupportedLangVersion)' == '' ">8.0</MaxSupportedLangVersion>

and change it to:

	<LangVersion Condition=" '$(LangVersion)' == '' ">8.0</LangVersion>

This matches [Roslyn's default behavior][1]:

.NET 5+ projects should be unaffected by this change, as they do not
import `Xamarin.Android.CSharp.targets`.

If at some point, if mono/mono/2020-02 fully supports C# 9 we can bump
this value.  Users can opt into `9.0` on their own if desired.

`BuildTest.CSharp8Features()` now passes for me locally.

[0]: dotnet/roslyn@12f1b8f#diff-125e2d8c52dd9033f9b248f79f78c3f8
[1]: https://github.com/dotnet/roslyn/blob/1aeda2e94fb9371b96d4bfd94b074860064ec3d2/src/Compilers/Core/MSBuildTask/Microsoft.CSharp.Core.targets#L6-L21
@jonathanpeppers jonathanpeppers deleted the fix-csharp-8 branch August 28, 2020 19:21
@jonathanpeppers jonathanpeppers mentioned this pull request Sep 22, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some of the C#8 features don't compile - Visual Studio v16.7.2

4 participants