.net EF Core 添加迁移构建失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44785540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:57:00  来源:igfitidea点击:

EF Core add-migration Build Failed

.netentity-frameworkasp.net-core.net-coreef-migrations

提问by jceddy

I have a developer that is getting "Build failed." when running add-migration in a .NET Core EF project, with no explanation of why the build failed. How do you troubleshoot this error?

我有一个开发人员收到“构建失败”的消息。在 .NET Core EF 项目中运行 add-migration 时,没有解释构建失败的原因。您如何解决此错误?

This is what he gets in the Package Manager Console:enter image description here

这是他在包管理器控制台中得到的:在此处输入图片说明

Additional information:

附加信息

We have a few other developers using the same solution code (myself included) that have not issues with add-migration.

我们还有一些其他开发人员使用相同的解决方案代码(包括我自己),他们没有添加迁移问题。

This is what I see in Package Manager Console:enter image description here

这是我在包管理器控制台中看到的:在此处输入图片说明

We've verified that the project builds, and the entire solution builds. We've done "dotnet restore" and rebuild all multiple times, in addition to restarting VS2015. We've verified that the correct default solution is selected both in Solution Explorer, and in the Package Manager Console drop-down. We've verified that he has the correct SDK installed on his machine. I'm at a loss as to what to check next...any time I've had a failure during add-migration I've gotten enough information to point me in the direction of what to check, but just "Build failed." is a fairly useless error output.

我们已验证项目已构建,并且整个解决方案已构建。除了重新启动 VS2015 之外,我们已经多次完成“dotnet restore”并重建所有内容。我们已经验证在解决方案资源管理器和包管理器控制台下拉列表中都选择了正确的默认解决方案。我们已经验证他在他的机器上安装了正确的 SDK。我不知道接下来要检查什么……每当我在添加迁移过程中出现故障时,我都会获得足够的信息来指明要检查的方向,但只是“构建失败。 ” 是一个相当无用的错误输出。

采纳答案by jceddy

The developer ended up un-mapping the project from TFS, deleting it, and re-mapping it. It's now working for him.

开发人员最终从 TFS 取消映射项目,删除它,然后重新映射它。现在它正在为他工作。

回答by mmh18

It's because of other projects in your solutions. e.g If you have two projects in your solution as Project A and Project B. If Project A is not successful build and then Project B data migration will fail. So you should unload Project A and add the migration to Project B again.

这是因为您的解决方案中有其他项目。例如,如果您的解决方案中有两个项目,分别是项目 A 和项目 B。如果项目 A 未成功构建,则项目 B 数据迁移将失败。因此,您应该卸载项目 A 并再次将迁移添加到项目 B。

I think this is not a good answer but hope this help.

我认为这不是一个好的答案,但希望能有所帮助。

回答by Makla

I had exact same problem (.NET Core 2.0.1).

我遇到了完全相同的问题(.NET Core 2.0.1)。

Sometimes helps if project is rebuild.

如果项目正在重建,有时会有所帮助。

I also encounter problem when I opened project in 2 Visual studios.
Closing one Visual Studio fixed error.

我在 2 个 Visual Studio 中打开项目时也遇到问题。
关闭一个 Visual Studio 修复了错误。

回答by Romain Vergnory

I suggest adding -vto have more info.

我建议添加-v以获取更多信息。

In my example, I had to add <LangVersion>latest</LangVersion>to my projects, as this was missing from some of them.

在我的示例中,我不得不添加 <LangVersion>latest</LangVersion>到我的项目中,因为其中一些项目中缺少这一点。

回答by Liam Kernighan

In my situation it was the error

在我的情况下,这是错误

namespace aspnetcore does not exist .. are you missing a reference?

I have figured it out by adding the -v (or --verbose) flag to the dotnet ef command.

我已经通过向 dotnet ef 命令添加 -v(或 --verbose)标志来解决这个问题。

回答by Bharat chaudhari

Try It:
1. first clean solution
2. build every project seperately.
3. resolved error if found (sometimes VS not showing errors until u build it seperately)
4. then try to run migration again

试试看:
1. 第一个干净的解决方案
2. 单独构建每个项目。
3. 如果找到则解决错误(有时 VS 不显示错误,直到您单独构建它)
4. 然后再次尝试运行迁移

回答by Leniel Maccaferri

I was struggling with this one while using Visual Studio 2019 version 16.5.0.

我在使用 Visual Studio 2019 版本 16.5.0 时遇到了这个问题。

What solved it finally:

最后解决了什么:

  • Close Visual Studio;
  • Reopen Visual Studio;
  • Make sure you right click the Solution if you have multiple projects and select Rebuild Solution.
  • 关闭 Visual Studio;
  • 重新打开 Visual Studio;
  • 如果您有多个项目,请确保右键单击解决方案并选择Rebuild Solution

Note that I tried doing a Rebuild Solutionbefore and that did not catch the error. So it's important to close VS and reopen it.

请注意,我Rebuild Solution之前尝试过,但没有发现错误。所以关闭VS并重新打开它很重要。

It then showed the error that was causing add-migrationcommand to fail with Build failedmessage.

然后它显示了导致add-migration命令失败并Build failed显示消息的错误。

回答by Metonymy

In my case the application was running. Apparently it needs to be stopped. Weird error message anyways.

在我的情况下,应用程序正在运行。显然它需要停止。无论如何,奇怪的错误消息。

回答by Archeg

Open Output window and check your build log. In my case even though my current configuration was Release, Add-Migrationbuilt the project in Debug, which had an error. For some reason, VS didn't display the error anywhere except Output window for me.

打开输出窗口并检查您的构建日志。在我的情况下,即使我当前的配置是Release,在 中Add-Migration构建了项目Debug,但有错误。出于某种原因,VS 没有为我在输出窗口之外的任何地方显示错误。

回答by Yaroslav

Had same situation. Helped next:

有同样的情况。接下来帮助:

  1. Open Package Manager Console
  2. Change directory to Migrationsfolder: cd C:\YourSolution\YourProjectWithMigrations
  3. Enter to PM: dotnet ef migrations add YourMigrationName
  1. 打开包管理器控制台
  2. 将目录更改为Migrations文件夹:cd C:\YourSolution\YourProjectWithMigrations
  3. 输入PM: dotnet ef migrations add YourMigrationName

回答by andrescpacheco

Just got into this issue. In my cause I was debugging my code and it was making my migrations to fail.

刚进入这个问题。在我的事业中,我正在调试我的代码,它使我的迁移失败。

Since in Visual Studio Code the debugger is so low profile (only a small bar) I didn't realize about this until I read some questions and decided to look better.

由于在 Visual Studio Code 中,调试器是如此低调(只有一个小条),直到我阅读了一些问题并决定看起来更好时,我才意识到这一点。

Just answering cause it might help someone.

只是回答因为它可能会帮助某人。