Reputation: 4483
I am trying to walk through this tutorial here.
https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro
However after successfully installing EntityFrameworkCore in the package manager console using the command:
Install-Package Microsoft.EntityFrameworkCore.SqlServer
then running a dotnet restore successfully in the cmd, the project does not register EntityFrameworkCore. In the .csproj file you can see the line
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
Unfortunately whenever I add a using statement with Microsoft.EntityFrameworkCore in a file I get the error mentioned in the title. Any idea why this might be happening?
Upvotes: 41
Views: 89494
Reputation: 1
I was faced same problem .. and it solved by rebuild my project solution while device connected to the internet because VS automatically download the missed packages. and this solution noted from first answer for this question.
Upvotes: 0
Reputation: 1
When installing the packages, the csproj get's edited to include references to Entity Framework, but is not being saved, so go to the csproj file by clicking on the project in visual studio and save it.
Upvotes: 0
Reputation: 1263
I was also having same error of nuget packages
not loading properly as visual studio was opened for long time. I simply restarted visual studio and all nuget packages
loaded successfully and error resolved.
Upvotes: -1
Reputation: 111
I've passed for something similar. The dependencies were installed but VSCode was not recognizing them (red waved line under the references).
I ran: ctrl + shift + p
and then .NET Restart Language Server
.
Upvotes: 0
Reputation: 1
I had the same problem in Visual Studio Code, it was decided that it was necessary to choose a project in which an error with the help of Omnisharp:Select Project through the ctrl + shift + p
Upvotes: -1
Reputation: 1
Use the nugget packege manager on VS code and add Microsoft.EntityFrameworkCore that way and the issue will be solved it will also place it into the .csproj
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.16"/>
Upvotes: -1
Reputation: 159
I am assuming this is the same issue I encountered with: https://learn.microsoft.com/en-us/aspnet/core/tutorials/razor-pages/?view=aspnetcore-6.0
The getting started directions include a section that lead you to believe you need to add the following -
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using RazorPagesMovie.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddDbContext<RazorPagesMovieContext>(options =>
options.UseSqlServer(builder.Configuration.GetConnectionString("RazorPagesMovieContext")));
var app = builder.Build();
However I determined that if you skip this and continue the tutorial, it is handled later on...
Upvotes: 1
Reputation: 81
If using VS Code, the solution that worked for me:
In the terminal type:
dotnet add package Microsoft.EntityFrameworkCore
After adding package, Ctrl + Shift + P
-> Restart OmniSharp
Upvotes: 8
Reputation: 618
In visual Studio, go to -> Project -> Manage NuGet Packages.. ->
Select Microsoft Entity framework Core. The click on Add package on the bottom right corner button.
Upvotes: 3
Reputation: 69
type->
install-package microsoft.entityframeworkcore.sqlserver
Upvotes: 1
Reputation: 3265
I had to lower the version of Entity Framework from 6.2 to 6.0
Upvotes: -1
Reputation: 131
Go to NuGet browser and install Microsoft.EntityFrameworkCore!
Upvotes: 12
Reputation: 112
From one of the other comments about the package.config file, double checking... Seems, my issue appeared that the targetFramework="net472" in the package.config file didn't match the project's .Net version. The project is using 4.7.2 but the package file was "471", updating the targetFramework in the package.config to "472" the problems went away :)
Seem in the past never had many issues with mixing 4.x.y, as long as 4.x were the same no troubles, as of late, sure seems .Net want 4.x.y to all match...
`<packages>
<package id="EntityFramework" version="6.2.0" targetFramework="net472" />
</packages>`
Upvotes: 0
Reputation: 51
Clean up the .csproj file so if you see something like...
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
Change it to :
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4" />
Upvotes: 1
Reputation: 619
You missed a required Nuget Package, according to microsoft, you will need to install 3 packages in total, but in my case, it is only required 2 packages as the following:
Hope this can solve your problem.
Upvotes: 9
Reputation: 51
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.
<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
Upvotes: 5
Reputation: 4483
I solved this problem by:
(1) Right clicking the project in the Solution Explorer
(2) Clicking unload project
(3) Click edit the .csproj and check if there is a Package Reference to EF
(4) Right clicking the project again in the Solution Explorer
(5) Then clicked reload project
Now it recognizes EntityFrameworkCore and there are no more build errors
Upvotes: 68