Skip to content

ImplicitNamespaceImports generated codefile generates an invalid import if you try to import as an alias. #19446

Closed
@AraHaan

Description

@AraHaan

Let's say for example I try to import these:

<Import Include="System" />
<Import Include="System.Collections.Generic" />
<Import Include="System.CommandLine" />
<Import Include="System.CommandLine.Help" />
<Import Include="System.CommandLine.Invocation" />
<Import Include="System.CommandLine.IO" />
<Import Include="System.Globalization" />
<Import Include="System.IO" />
<Import Include="System.Linq" />
<Import Include="System.Reflection" />
<Import Include="System.Text" />
<Import Include="System.Threading.Tasks" />
<Import Include="Elskom.Generic.Libs" />
<Import Include="Microsoft.Diagnostics.NETCore.Client" />
<Import Include="newsmakeResources = Elskom.Generic.Libs.Properties" />

The resulting generated <project name>.ImplicitNamespaceImports.cs file will contain:

// <autogenerated />
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
global using global::System.CommandLine;
global using global::System.CommandLine.Help;
global using global::System.CommandLine.Invocation;
global using global::System.CommandLine.IO;
global using global::System.Globalization;
global using global::System.Reflection;
global using global::System.Text;
global using global::Elskom.Generic.Libs;
global using global::Microsoft.Diagnostics.NETCore.Client;
global using global::newsmakeResources = Elskom.Generic.Libs.Properties;

Which results in: <project name>/obj/Debug/net6.0/<project name>.ImplicitNamespaceImports.cs(18,40): error CS1525: Invalid expression term '='

I feel like whereever in the .NET SDK that generates that file that it should actully explicitly look for things like =, static, etc before it tries to insert global:: then insert it after it finds static and/or = so that way the compilation would work.

My .NET SDK version currently is: 6.0.100-rc.1.21366.58.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions