简体   繁体   中英

'EntityFrameworkCore' does not exist in the namespace 'Microsoft'

I follow this tutorial: https://docs.microsoft.com/en-us/ef/core/get-started/full-dotnet/new-db step by step

but I cannot add the "Microsoft.EntityFrameworkCore " namespace to Model.cs

I use Visual studio 2017

and install Microsoft.EntityFrameworkCore.SqlServer(1.1.2) ,

Microsoft.EntityFrameworkCore.Tools (1.1.1) ,

and .NET Framework 4.5.2

Visual Studio says:

The type or namespace name 'EntityFrameworkCore' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

They added to .csproj :

在此处输入图像描述

Copying the following code into the TodoApi.csproj from https://github.com/aspnet/Docs/tree/master/aspnetcore/tutorials/first-web-api/sample/TodoApi worked for me on a similar issue.

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
  </ItemGroup>

</Project>

Microsoft.AspNetCore.All may be excessive but it includes EntityFrameworkCore etc

C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets(90,5): Error: The Microsoft.AspNetCore.All package is not supported when targeting .NET Core 3.0 or higher. A FrameworkReference to Microsoft.AspNetCore.App should be used instead, and will be implicitly included by Microsoft.NET.Sdk.Web.

For anyone at 3.0 or higher with same error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM