【问题标题】:Could not load assembly... Ensure it is referenced by the startup project无法加载程序集...确保它被启动项目引用
【发布时间】:2021-01-25 09:52:47
【问题描述】:

有一个“Data”项目包含app的上下文,根项目“TheFarmersMarketApp”参考Data项目。主要项目是在 WPF 上编写的。

Add-Migration "Initial Migration" -Project Data -StartUpProject TheFarmersMarketApp

返回

Could not load assembly 'Data'. Ensure it is referenced by the startup project 'TheFarmersMarketApp'.

此外,我更改了“数据”和“模型”(呃...)项目上的“默认项目”字段,并重新启动了我的笔记本电脑以确保所有必要的服务都已打开。

有一些Visual Studio的截图,如果视觉上更容易理解问题。

PackageManagerConsole + SolutionExplorer + TheFarmersMarket.csproj windows

Output after rebuilding + ErrorList windows.

【问题讨论】:

  • 重建项目数据,看看有没有错误。

标签: c# xml wpf entity-framework-core entity-framework-core-migrations


【解决方案1】:
Could not load assembly 'Data'. Ensure it is referenced by the startup project 'TheFarmersMarketApp'.

请确保将 Data 程序集添加到项目 TheFarmersMarketApp 中。请确保所有需要引用这个项目的项目都直接引用它,只要它不会导致循环依赖或其他问题。

【讨论】:

    【解决方案2】:

    首先,您需要在 Nuget 包管理器控制台中选择一个合适的项目。正如您在第一个屏幕上看到的,默认项目是 TheFarmersMarketApp,但它不正确。您需要选择 Data 项目,因为您的迁移必须位于您的上下文类附近。

    那么你应该使用你的命令的简短版本:

    Add-Migration "Initial Migration" 
    

    【讨论】:

      【解决方案3】:

      我遇到了这样的问题。经过几个小时的修复,我发现问题出在 Package Manager ConsoleVisual Studio CLI

      我使用了 Windows 命令提示符dotnet 工具

      > dotnet ef migrations add migration_name
      

      执行命令后成功,没有任何错误提示:

      > Done. To undo this action, use 'ef migrations remove
      

      【讨论】:

        猜你喜欢
        • 2021-07-08
        • 2021-02-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多