c# - 'IServiceCollection' 不包含 'AddMvc' 的定义, 'IApplicationBuilder' 不包含 'UseStaticFiles' 的定义,

标签 c# asp.net-core asp.net-core-mvc visual-studio-code .net-core

我使用以下命令创建了 .net core 2.0 mvc 应用程序:“dotnet new mvc”,它运行没有任何问题,但在 vscode 中我有两个错误:

'IServiceCollection' does not contain a definition for 'AddMvc' and no extension method 'AddMvc' accepting a first argument of type 'IServiceCollection' could be found (are you missing a using directive or an assembly reference?)'

'IApplicationBuilder' does not contain a definition for 'UseStaticFiles' and no extension method 'UseStaticFiles' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?) '

我正在使用:Linux elementary OS 0.4.1 Loki、.net core 2.0、vscode 1.15.1。

最佳答案

加载项目时,您的 Nuget 还原可能失败。尝试从命令行运行 dotnet restore

还要检查以确保在使用 .AddMVC().UseStaticFiles( )

关于c# - 'IServiceCollection' 不包含 'AddMvc' 的定义, 'IApplicationBuilder' 不包含 'UseStaticFiles' 的定义,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45763970/

相关文章:

asp.net-core - .Net Core 2.0 NuGet 文件位置是什么

c# - 如何禁用 ASP.NET Web 服务客户端请求的保持事件状态?

c# - 如何创建无需用户交互即可自行更新的 Windows 服务

asp.net-core - 从 ASP.NET Core 中的列表实现复选框列表

c# - StackExchange.Redis.RedisTimeoutException - 由于问题人们如何解决它?

azure - 如何将 Easy Auth 与 .NET Core 3.1 MVC 应用程序集成?

c# - Lambda 表达式练习

c# - 如何在 EnumMember 属性中添加多个值?

c# - 具有 Windows 身份验证的 ASP.NET Core 身份

c# - DI 到 ASP.NET MVC 6 中的需求/策略