Skip to content
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

Merged

Commits on Aug 23, 2021

  1. [One .NET] support latest C# 10 language features

    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>
    jonathanpeppers committed Aug 23, 2021
    Configuration menu
    Copy the full SHA
    218a708 View commit details
    Browse the repository at this point in the history