新建.NET WebAPI项目后出现命名空间缺失等编译错误如何解决
新建Web API项目命名空间缺失报错解决方案
项目创建操作
通过以下命令新建Web API项目:
dotnet new webapi -o TodoApi cd TodoApi dotnet add package Microsoft.EntityFrameworkCore.InMemory --prerelease code -r ../TodoApi
问题表现
项目创建完成后出现全量命名空间缺失问题,共触发26个编译错误,典型报错示例如下:
The type or namespace name 'ILogger<>' could not be found (are you missing a using directive or an assembly reference?) [PaymentApi](未找到类型或命名空间名称'ILogger<>',是否缺少using指令或程序集引用)The name 'WebApplication' does not exist in the current context [TechnePaymentApi](当前上下文中不存在名称'WebApplication')A namespace cannot directly contain members such as fields or methods [TechnePaymentApi](命名空间不能直接包含字段、方法等成员)
错误截图:
已验证解决方案
该问题由VS Code和C#插件版本过低导致,将两者升级到最新版本后重新创建ASP.NET Core 6.0项目即可消除所有报错。
内容的提问来源于stack exchange,提问作者hanushic
相关产品推荐
相关产品推荐

