-
Notifications
You must be signed in to change notification settings - Fork 533
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
[One .NET] support latest C# 10 language features #6118
[One .NET] support latest C# 10 language features #6118
Conversation
This is a draft, because I suspect we might get test failures on this one. |
...d.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.ImplicitNamespaceImports.targets
Outdated
Show resolved
Hide resolved
...d.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.ImplicitNamespaceImports.targets
Outdated
Show resolved
Hide resolved
...d.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.ImplicitNamespaceImports.targets
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj
Outdated
Show resolved
Hide resolved
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj
Show resolved
Hide resolved
One complication that came up in a test:
So I suspect that dotnet/maui is going to set |
e628acd
to
245ec40
Compare
This suggests that we might not want Will The "better answer" here may be to just not add anything to |
Context: dotnet/android#6118 Running into issues with C# 10 global usings, because Xamarin.Legacy.Sdk is building with C# 8.0 by default.
245ec40
to
f7a5e1d
Compare
fdd34a1
to
8004dd1
Compare
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/XASdkTests.cs
Outdated
Show resolved
Hide resolved
"assemblies/UnnamedProject.dll": { | ||
"Size": 3171 | ||
"Size": 3535 |
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.
Adding Nullable=enable
, increased this assembly's size enough to fail the test...
Error: apkdiff: File 'assemblies/UnnamedProject.dll' has changed by 358 bytes (10.14 %). This exceeds the threshold of 5.00 %.
8004dd1
to
91c1ad9
Compare
91c1ad9
to
ce8f4b7
Compare
We need to wait on this, because there are changes to the .NET SDK coming:
See: dotnet/sdk#19535 (comment) I'd rather wait for the final implementation to land before we opt into the changes here. |
The MAUI targets can remove the Android global usings, or make aliasing choices. |
1064f4f
to
2443637
Compare
43e480a
to
9e96e08
Compare
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", | ||
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_FORMS_INIT}", |
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 found this test was not using a Forms-based MainActivity.cs
before, but it was a Xamarin.Forms app! So we need to use ${AFTER_FORMS_INIT}
now and the line number changed.
9e96e08
to
e42680b
Compare
Context: dotnet/sdk#19521 Fixes: dotnet#6075 Fixes: dotnet#6076 We need to make two sets of changes for C# 10: 1. Support "global usings". Our .NET 6 templates should have no `using` statements at the top of `.cs` files. 2. Use `$(Nullable)` `enable` by default in project templates. 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`. So `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 these items are present at the time `.csproj` files are evaluated. 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>
e42680b
to
218a708
Compare
@@ -3,5 +3,7 @@ | |||
<TargetFramework>net6.0-android</TargetFramework> | |||
<SupportedOSPlatformVersion>SUPPORTED_OS_PLATFORM_VERSION</SupportedOSPlatformVersion> | |||
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">AndroidBinding1</RootNamespace> | |||
<Nullable>enable</Nullable> | |||
<ImplicitUsings>enable</ImplicitUsings> |
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.
Should we update AndroidBinding1.csproj
to also set $(AndroidGenerateResourceDesigner)
=False, as per #6224?
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.
You can have an .aar
with resources, then you might want to use Resource.designer.cs
values from C#.
So I don't think we need this by default, but it's there if you need to turn it off.
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-references
Context: dotnet/sdk#19521
Fixes: #6075
Fixes: #6076
We need to make two sets of changes for C# 10:
using
statements at the top of.cs
files.$(Nullable)
enable
by default in project templates.To test this, our .NET 6 MSBuild tests use
Nullable=enable
andImplicitUsings=enable
by default and do not includeusing
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:The last one is intentionally not bringing in
Android.OS
, becauseAndroid.OS.Environment
would conflict withSystem.Environment
.So
AutoImport.props
should become:So these items are present at the time
.csproj
files are evaluated.Any templates will add:
If users want to configure these settings, they can remove
$(ImplicitUsings)
from the.csproj
completely or remove specific@(Using)
items: