C# (生成失败)添加迁移初始值

C# (生成失败)添加迁移初始值,c#,.net,C#,.net,我正在学习.NET上的一门课程 我需要在Package Manager控制台的PieController.cs文件下编写“Add Migration Initial” 当我这样做时,我会收到一条没有错误列表的“构建失败”消息 导致生成失败的问题是什么 using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.

我正在学习.NET上的一门课程

我需要在Package Manager控制台的PieController.cs文件下编写“Add Migration Initial”

当我这样做时,我会收到一条没有错误列表的“构建失败”消息

导致生成失败的问题是什么

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BethanysPieShop.Models;
using BethanysPieShop.ViewModels;


namespace BethanysPieShop.Controllers
{
    public class PieController : Controller
    {
        private readonly IPieRepository _pieRepository;
        private readonly ICategoryRepository _categoryRepository;

        public PieController(IPieRepository pieRepository, ICategoryRepository categoryRepository)
        {
            _pieRepository = pieRepository;
            _categoryRepository = categoryRepository;
        }

        public ViewResult List()
        {
            PiesListViewModel piesListViewModel = new PiesListViewModel();
            piesListViewModel.Pies = _pieRepository.Pies;

            piesListViewModel.CurrentCategory = "Cheese cakes";

            return View(piesListViewModel);
        }

    }
}
课程成绩如下(1)


以下是您可以执行的一些操作:

  • 关闭并再次打开VisualStudio,清理并重新生成项目,然后再次运行添加迁移
  • 检查是否存在生成错误
  • 检查是否存在外键错误或数据库架构错误

当然,有些东西或某些错误无法使迁移做好准备。

在我的情况下,相同的问题是由于我的主项目引用了另一个具有不同版本的EFCore的项目而引起的。因此,在管理迁移之前,我必须删除项目引用。在所有链接的项目中使用相同的EF版本也应该是一个解决方案。

根据我的经验,这是由其他错误引起的,在纠正错误后,它起作用了。在_ViewStart.cshtml中,我必须将Layout=_Layout更改为Layout=“_Layout”


在其他情况下,可能是由于其他错误。

-我的项目名为WebApplication5close and open vscode,在安装
dotnet工具安装之后为我解决了此问题--global dotnet ef--版本3.1.5