问题
I am getting the following error when adding an asp.net core api to an existing project I am working on.
"Version Conflict detected for Microsoft.EntityFrameworkCore.Install/reference Microsoft.EntityFrameworkCore 2.2.1 directly to project to resolve this issue"
I tried to add the Nuget package but get further version conflicts across a number of different packages and the process always fails. At first I thought this may be an issue with my project so I started a new solution from scratch and managed to replicate the issue with a few simple steps.
- Create a new solution (EFDemo)
- Add a new .net Core class library to the solution called EFDemo.BL
- Add the following Nuget packages to project EFDemo.BL (as I'm using an existing database for my new project)
- Microsoft.EntityFrameworkCore.SqlServer (v2.2.1)
- Microsoft.EntityFraneworkCore.Tools (v2.2.1)
- Add a new .net core web application called EFDemo.Api and select the API project template.
- Add a reference from EFDemo.BL to EFDemo.Api.
- Build and see the failure.
I have reviewed the following post but its solution does not work for me as I have no reference to "Microsoft.EntityFrameworkCore" in any of my csproj files. Version conflict detected for NuGet packages.
I have also reinstalled .net SDK, rebooted a million times and still can't understand what the issue is.
回答1:
I have encountered the same error recently.
What I have done to sort this out:
Installed .Net Core 2.2 SDK
Then in my project I have changed in all .csproj files:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
whereas before it was:
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
This helped straight away and the error dissapeared.
回答2:
The answer to this is quite difficult to catalog because I made many changes while trying to figure this out. In the end, I believe the following steps fixed my issue:
- Upgrade VS to the latest version (v15.9.3)
- Uninstall both .Net Core 2.1 and 2.2 SDKs (my project was using 2.1 at the time)
- Install .Net Core 2.2 SDK
- Convert all projects in my solution to use .Net Core 2.2 (A pain. I wish there was a Retarget All function!)
- Reboot, Clean, Build and it works. Phew.
Now to do some work instead of fighting with my tools!
回答3:
For me, it helped this article, it was a very simple change on the configuration, which I forgot to change:
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
https://dotnetcoretutorials.com/2018/11/18/how-to-target-net-core-2-2/
回答4:
I fixed this just installing .NET Core 2.2 and changing TargetFramework tag to netcoreapp2.
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
回答5:
I am not sure what package you have installed in your project.
But now days visual studio add just one nuget packages which includes all of required package for asp.net core application.
Try installing this package and remove all other package and see it that works for you.
Microsoft.AspNetCore.All
This way you will not have version conflict at least within Microsoft packages. You can then verify other external package that you might have installed which is causing problem.
回答6:
This helped for me and saved me frustrations
<TargetFramework>netcoreapp2.2</>
回答7:
- Download and install the latest framwork (dotnet coro 2.2 in my case)
- set project target framework to highest (dotnet coro 2.2 in my case) from project properties
- Clean solution 4 Rebuild solution
- Update any version disputes (optional)
- Rebuild and save.
- Boooommm.. you are good to go.
来源:https://stackoverflow.com/questions/54323167/version-conflict-detected-for-microsoft-entityframeworkcore-install