Uh oh!
There was an error while loading. Please reload this page.
[One .NET] support latest C# 10 language features - #6118
Conversation
jonathanpeppers
commented
Jul 23, 2021
This is a draft, because I suspect we might get test failures on this one. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
jonathanpeppers
commented
Jul 23, 2021
One complication that came up in a test: So I suspect that dotnet/maui is going to set |
e628acd to
245ec40Comparejonpryor
commented
Jul 26, 2021
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
f7a5e1dComparefdd34a1 to
8004dd1CompareUh oh!
There was an error while loading. Please reload this page.
| "assemblies/UnnamedProject.dll": { | ||
| "Size": 3171 | ||
| "Size": 3535 |
There was a problem hiding this comment.
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
91c1ad9Compare91c1ad9 to
ce8f4b7Comparejonathanpeppers
commented
Aug 6, 2021
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. |
mhutch
commented
Aug 11, 2021
The MAUI targets can remove the Android global usings, or make aliasing choices. |
1064f4f to
2443637Compare43e480a to
9e96e08Compare| proj.SetAndroidSupportedAbis ("armeabi-v7a", "arm64-v8a", "x86", "x86_64"); | ||
| proj.SetProperty (proj.ReleaseProperties, "MonoSymbolArchive", "True"); | ||
| proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_ONCREATE}", | ||
| proj.MainActivity = proj.DefaultMainActivity.Replace ("//${AFTER_FORMS_INIT}", |
There was a problem hiding this comment.
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
e42680bCompareContext: dotnet/sdk#19521Fixes: dotnet#6075Fixes: 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
218a708Compare| <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.
Should we update AndroidBinding1.csproj to also set $(AndroidGenerateResourceDesigner)=False, as per #6224?
There was a problem hiding this comment.
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: #6075Fixes: #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:
usingstatements at the top of.csfiles.$(Nullable)enableby default in project templates.To test this, our .NET 6 MSBuild tests use
Nullable=enableandImplicitUsings=enableby default and do not includeusingstatements in
.csfiles.I've made a new
MainActivity.csfor our .NET 6 MSBuild tests. The"legacy" Xamarin.Android tests will use the original file.
Our default
global usingare:The last one is intentionally not bringing in
Android.OS, becauseAndroid.OS.Environmentwould conflict withSystem.Environment.So
AutoImport.propsshould become:So these items are present at the time
.csprojfiles are evaluated.Any templates will add:
If users want to configure these settings, they can remove
$(ImplicitUsings)from the.csprojcompletely or remove specific@(Using)items: