Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project

[亡魂溺海] 提交于 2019-11-30 02:20:00

问题


I've been researching a lot online but did not find a proper solution. I was trying to use Entity Framework Core with MySQL by using database-first scaffold method to mapping table model while always received this error when applied the command

Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.

This is the command I am using to scaffold the database model:

Scaffold-DbContext "server=localhost;port=3306;user=root;password=1234;database=world" "Pomelo.EntityFrameworkCore.MySql" -OutputDir .\Models -f

And this is my .Net Core project setting:

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.1" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
  </ItemGroup>

回答1:


For my case this error was solved by downloading latest dotnet-sdk-2.2.107-win-x64

for VS2017 and then dropping and updating database through cmd:

dotnet ef database drop --force --context <<dbcontext>> -s <<startup project directory>> -p <<project directory>>


dotnet ef database update --context <<dbcontext>> -s <<startup project directory>> -p <<project directory>>



回答2:


I have tried different solutions to solve this error. Did following change in .csproj file.

Solved this issue for .Net Core by edit .csproj file and removed Import tag and then run ef command again in command line.




回答3:


For EF Core 3

I think the powershell command has gone away for EF Core 3 so I'm using dotnet ef dbcontext scaffold

With this command, if you're converting a Scaffold-DbContext script the project name (parameter --project) needs to have .csproj on the end - it can't just the extensionless name.




回答4:


I got this error trying to add a new migration on the command line with dotnet ef migrations add NewMigration.

The solution for me was indeed to append --msbuildprojectextentionspath obj/local.




回答5:


Add this parameter to the end of your scaffold command "--msbuildprojectextensionspath".



来源:https://stackoverflow.com/questions/50672815/unable-to-retrieve-project-metadata-ensure-its-an-msbuild-based-net-core-proj

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!