Entity Framework Core 8.0.1迁移报错:目标GetEFProjectMetadata不存在
EF Core 8.0.1迁移报错Error MSB4057的排查方案
执行迁移命令时出现以下错误:
Error MSB4057: The target "GetEFProjectMetadata" does not exist in the project. 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.
命令:dotnet ef migrations add CustomerEntityUpdate -p X -s Y
此前配置正常,仅修改了实体类,未更改路径设置。
- 检查目标项目的SDK配置:打开项目X的
.csproj文件,确认顶部声明为<Project Sdk="Microsoft.NET.Sdk">(类库项目)或对应Web SDK,排除非MSBuild格式的项目类型。 - 清理重建项目:执行以下命令清除损坏的中间文件,重新生成元数据:
dotnet clean dotnet build - 显式指定MSBuild扩展路径:即使未修改路径,也可能因中间文件异常导致解析失败,尝试添加参数指向项目X的
obj目录:dotnet ef migrations add CustomerEntityUpdate -p X -s Y --msbuildprojectextensionspath X/obj - 对齐EF Core工具版本:执行
dotnet ef --version查看工具版本,确保与项目引用的8.0.1一致,版本不符则更新:dotnet tool update --global dotnet-ef --version 8.0.1 - 验证实体类修改:确认实体类的更改未破坏DbContext配置,比如新增属性的映射是否正确,项目能否正常编译。
- 切换路径执行命令:进入项目X的根目录,执行迁移命令并指定启动项目路径:
dotnet ef migrations add CustomerEntityUpdate -s ../Y
内容的提问来源于stack exchange,提问作者YOUSSEF
相关产品推荐
相关产品推荐

