You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code无法识别EF Core包问题求助(首次使用VS Code)

解决VS Code中EF Core包无法识别的问题

第一步:修复csproj文件中的错误依赖

你的项目存在两个关键依赖问题:

  • Microsoft.EntityFrameworkCore.Tools.DotNet:该包是EF Core早期版本的工具包,从.NET Core 2.1起已被整合到Microsoft.EntityFrameworkCore.Tools中,且你安装的2.0.3版本与net7.0完全不兼容,直接删除此引用。
  • System.Data.Entity.Repository:这是Entity Framework 6(非Core版本)的包,与EF Core API完全冲突,会导致命名空间识别异常,必须移除。

修改后的csproj内容如下:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>

</Project>

第二步:重新还原并构建项目

在终端依次执行以下命令:

  • 清理项目:dotnet clean
  • 还原依赖:dotnet restore
  • 重新构建:dotnet build

第三步:修复VS Code IntelliSense异常

  1. 关闭VS Code,删除项目根目录下的.vs、bin、obj文件夹
  2. 重新打开VS Code,等待OmniSharp语言服务加载完成(右下角会有状态提示)
  3. 若仍有问题,按Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(Mac),输入OmniSharp: Restart OmniSharp重启服务

额外提示

你之前使用的dotnet install packag <包名>是错误命令,正确的包安装命令为dotnet add package <包名>,后续操作注意避免拼写错误。

内容的提问来源于stack exchange,提问作者ISquared

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 06:33:19