Commit 5e730fc
committed
[One .NET] support latest C# 10 language features (#6118)
Fixes: #6075
Fixes: #6076
Context: dotnet/sdk#19521
We need to make two sets of changes for C# 10:
1. Support ["global usings"][0]. Our .NET 6 templates should have no
`using` statements at the top of `.cs` files.
2. Set `$(Nullable)`=enable by default in project templates, i.e.
enable [C#8 nullable reference types][1] by default.
To test this, our .NET 6 MSBuild tests use `$(Nullable)`=enable and
`$(ImplicitUsings)`=enable by default and do not include `using`
statements in `.cs` files.
I've made a new `MainActivity.cs` for our .NET 6 MSBuild tests.
The "legacy" Xamarin.Android tests will use the original file.
Our default `global using` are:
global using global::Android.App;
global using global::Android.Widget;
global using Bundle = global::Android.OS.Bundle;
The last one is intentionally not bringing in `Android.OS`, because
`Android.OS.Environment` would conflict with `System.Environment`,
and the `System` namespace will be in `@(Using)` by default.
`AutoImport.props` should become:
<ItemGroup Condition=" '$(TargetPlatformIdentifier)' == 'android' and ('$(ImplicitUsings)' == 'true' or '$(ImplicitUsings)' == 'enable') ">
<Using Include="Android.App" />
<Using Include="Android.Widget" />
<Using Include="Android.OS.Bundle" Alias="Bundle" />
</ItemGroup>
so that these `using`s are present at the time `.csproj` files are
compiled.
Any templates will add:
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
If users want to configure these settings, they can remove
`$(ImplicitUsings)` from the `.csproj` completely, or remove specific
`@(Using)` items:
<ItemGroup>
<Using Remove="Android.App" />
</ItemGroup>
[0]: https://github.com/dotnet/csharplang/blob/b89d4c934041db923f7238b1427cd5f3ae71ed4b/proposals/csharp-10.0/GlobalUsingDirective.md#global-using-alias-directives
[1]: https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references1 parent 2028600 commit 5e730fc
File tree
20 files changed
+76
-96
lines changed- src
- Microsoft.Android.Templates
- android-activity
- android-bindinglib
- androidlib
- android
- Xamarin.Android.Build.Tasks
- Microsoft.Android.Sdk/Sdk
- Tests
- Xamarin.Android.Build.Tests
- Utilities
- Xamarin.ProjectTools
- Android
- Resources
- Base
- DotNet
- tests/MSBuildDeviceIntegration/Tests
20 files changed
+76
-96
lines changedLines changed: 1 addition & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | 1 | | |
7 | 2 | | |
8 | 3 | | |
9 | 4 | | |
10 | 5 | | |
11 | | - | |
| 6 | + | |
12 | 7 | | |
13 | 8 | | |
14 | 9 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | 1 | | |
7 | 2 | | |
8 | 3 | | |
9 | 4 | | |
10 | 5 | | |
11 | | - | |
| 6 | + | |
12 | 7 | | |
13 | 8 | | |
14 | 9 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | 1 | | |
4 | 2 | | |
5 | 3 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
23 | 29 | | |
24 | 30 | | |
25 | 31 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
208 | 209 | | |
209 | 210 | | |
210 | 211 | | |
| |||
550 | 551 | | |
551 | 552 | | |
552 | 553 | | |
553 | | - | |
| 554 | + | |
554 | 555 | | |
555 | 556 | | |
556 | 557 | | |
| |||
645 | 646 | | |
646 | 647 | | |
647 | 648 | | |
648 | | - | |
| 649 | + | |
649 | 650 | | |
650 | 651 | | |
651 | 652 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
0 commit comments