问题
I would like to Add-Migration
with my DbContext, but I get Error:
The term 'add-migration' is not recognized as the name of a cmdlet, function, script file, or operable program.
Is the problem related with folder structure? The customized User.cs, Role.cs and the Startup.cs are in different folders.
The Entity Framework is included in the DbContext project file.
How do I fix this?
回答1:
Is the problem related with folder structure?
This issue is not about the folder structure
.It's about the nuget packages
and you project's target framework
.
Nuget packages can bring the part of EF framework
to you. Just like Microsoft Unit Test
framework, we have to consume the MSTest.TestFramework
and MSTest.TestAdapter
packages in the project to make the test framework
work well.
As for your issue, the original cause can be that those packages are not loaded or incompatible in your current project.(Yellow warnings in pic 2).
Resolve the yellow warnings and install the Microsoft.EntityFrameworkCore
and Microsoft.EntityFrameworkCore.Tools
packages, then the command should work. See:
Red warnings in pic occurred before I install that two packages. After install them successfully, the command can be recognized well by current project.
Suggestions:
If you're not that familiar with how to resolve nuget issues(yellow warnings), share more details about it, your VS version, target framework, error messgae in Error List window...
And also I suggest you can create a new Asp.net core web app
to test it, do nothing but install those two packages successfully, then the Add-migration command can be recognized by your new project. Then you can confirm if something wrong with nuget packages in your current project that causes the issue, like what I said above.
Hope it makes some help :)
来源:https://stackoverflow.com/questions/58093181/how-to-use-add-migration-if-the-project-contains-multiple-folders