對VS 2019中ASP.NET Core項目解決:The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name


錯誤:

 

 

 

Add-Migration : The term 'Add-Migration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a p
ath was included, verify that the path is correct and try again.
At line:1 char:1
+ Add-Migration init
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Add-Migration:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

在本人這個環境下,對PowerShell的ExecutionPolicy也是執行了設置了的。之后的細節如下:

1、 編譯項目。首次在項目中添加EF Core后,這一步必須做,否則都找不到后續要導入的 EntityFrameworkCore.psd1 模塊。

2、找到前述文件的位置,使用Import-Module命令導入。我這里為: Import-Module C:\Users\{用戶名}\.nuget\packages\microsoft.entityframeworkcore.tools\1.1.1\tools\EntityFrameworkCore.psd1

執行信息如下:

PM> Import-Module C:\Users\*\.nuget\packages\microsoft.entityframeworkcore.tools\3.1.2\tools\EntityFrameworkCore.psd1

模塊“EntityFrameworkCore”中的某些導入命令的名稱包含未批准的動詞,這些動詞可能導致這些命令名不易被發現。若要查找具有未批准的動詞的命令,請使用 Verbose 參數再次運行 Import-Module 命令。有關批准的動詞列表,請鍵入 Get-Verb。

 

 

 

之后問題解決,執行Add-Migration Initial  ,Update-Database這些命令都正常了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM