[Xamarin.Android.Build.Tasks] fix C# 8.0 support by default#5054
Merged
jonpryor merged 1 commit intodotnet:masterfrom Aug 28, 2020
Merged
[Xamarin.Android.Build.Tasks] fix C# 8.0 support by default#5054jonpryor merged 1 commit intodotnet:masterfrom
jonpryor merged 1 commit intodotnet:masterfrom
Conversation
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.
jpobst
approved these changes
Aug 27, 2020
brendanzagaeski
approved these changes
Aug 27, 2020
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. |
Contributor
There was a problem hiding this comment.
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
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
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #5049
Context: dotnet/roslyn@12f1b8f#diff-125e2d8c52dd9033f9b248f79f78c3f8
Context: dotnet/roslyn#44911 (comment)
The
BuildTest.CSharp8Featurestest was failing for me locally whereI have Visual Studio 2019 16.7.2 installed:
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:
features like covariant return types and function pointers require
runtime changes.
$(LangVersion)is already being setto
9.0by default.We should just change the current behavior of:
And change it to:
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.0on their own if desired.BuildTest.CSharp8Featuresnow passes for me locally.