【问题标题】:'IServiceCollection' does not contain a definition for 'AddMvc', 'IApplicationBuilder' does not contain a definition for 'UseStaticFiles',“IServiceCollection”不包含“AddMvc”的定义,“IApplicationBuilder”不包含“UseStaticFiles”的定义,
【发布时间】:2018-01-27 13:44:15
【问题描述】:

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

“IServiceCollection”不包含“AddMvc”的定义,并且找不到接受“IServiceCollection”类型的第一个参数的扩展方法“AddMvc”(您是否缺少 using 指令或程序集引用?)'

“IApplicationBuilder”不包含“UseStaticFiles”的定义,并且找不到接受“IApplicationBuilder”类型的第一个参数的扩展方法“UseStaticFiles”(您是否缺少 using 指令或程序集引用?)'

我正在使用:Linux 基本操作系统 0.4.1 Loki、.net core 2.0、vscode 1.15.1。

【问题讨论】:

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


    【解决方案1】:

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

    还要检查以确保您在使用.AddMVC().UseStaticFiles() 的文件顶部有using Microsoft.Extensions.DependencyInjection

    【讨论】:

    【解决方案2】:

    我遇到了同样的问题,我通过在 .cproj 文件中添加以下包来解决它

    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.7" />

    并做了一个dotnet restore。我正在使用dotnet 3.1 版本。

    【讨论】:

      猜你喜欢
      • 2016-09-25
      • 2021-12-05
      • 2019-09-22
      • 2018-07-22
      • 2017-07-31
      • 1970-01-01
      • 1970-01-01
      • 2019-06-09
      • 2022-01-03
      相关资源
      最近更新 更多