ImplicitNamespaceImports generated codefile generates an invalid import if you try to import as an alias.
See original GitHub issueLet’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
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
python - Why can't I import from a module alias?
When I mentioned the term "portal" as a way to reference the variable created by the import statement, I meant to refer to...
Read more >BC40056: Namespace or type specified in the Imports ' ...
Make sure the namespace or the type is defined and contains at least one public member. Make sure the alias name doesn't contain...
Read more >using directive - C# Reference
Beginning with C# 12, you can create aliases for types that were previously restricted, including tuple types, pointer types, and other unsafe ...
Read more >useless-import-alias / C0414 - Pylint
Description: Used when an import alias is same as original package, e.g., using import numpy as numpy instead of import numpy as np....
Read more >How to request new Java features like import alias?
A lot better if the syntax was: import java.sql.Date as sql.Date;. Then you can't rename a class as anything misleading; you can only...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For C# projects yes, use
<Using>
rather than<Import>
, after https://github.com/dotnet/sdk/pull/19599 is merged.@wli3 @JunTaoLuo doesn’t wort at Microsoft anymore.
@AraHaan the change to support
<Using />
has been merged and is now available in daily builds of the SDK. As such I’m closing this issue. If you have any other problems please log a new issue.