Skip to content

More options for @(Import) and C# 10 global usings? #19535

@jonathanpeppers

Description

@jonathanpeppers

Context: dotnet/android#6118

We have an issue in .NET 6 Android applications, where every Android app has a method like:

protected override void OnCreate(Bundle? savedInstanceState)

We don't want to include <Import Include="Android.OS" />, because Android.OS.Environment would conflict with System.Environment. Developers would likely use System.Environment, so we don't want to cause an issue there.

So our plan is to add the global using:

global using Bundle = global::Android.OS.Bundle;

Unfortunately, it's not possible to use the @(Import) item group to do this, because it always prefixes global:::

<_ImportFileLine Include="global using global::%(_UniqueImport.Identity)%3B"/>

What we did for now is generate our own C# file for this one line.

This seems OK, but is it worth adding some support to @(Import) so you could do something like:

<Import Include="Bundle = global::Android.OS.Bundle" />

Maybe the dotnet/sdk could simply skip the global:: prefix if the string contains it?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions