1

我正在製作.Net Core上的教程,我無法使用軟件包管理器控制檯。找不到可執行文件匹配命令「dotnet-ef」(軟件包管理器)

我對這個Link

使本教程中,當我在包管理器控制檯寫插件遷移或更新DATEBASE(例):

DOTNET EF miggrations添加耶尼

事實證明這錯誤:

dotnet : No executable found matching command "dotnet-ef" 
At line:1 char:1 
+ dotnet ef miggrations add Yeni 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (No executable f...and "dotnet-ef":String) [], RemoteException 
    + FullyQualifiedErrorId : NativeCommandError 

我可以更新我的數據庫,還是可以在包管理器控制檯上添加新的遷移?如何 ?

這裏是我的projects.json

{ 
    "userSecretsId": "aspnet-WebApplication6-6e4c4aee-6cd6-4565-b603-7b4517839d9c", 

    "dependencies": { 
    "Microsoft.NETCore.App": { 
     "version": "1.0.0", 
     "type": "platform" 
    }, 
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0", 
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0", 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0", 
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0", 
    "Microsoft.AspNetCore.Mvc": "1.0.0", 
    "Microsoft.AspNetCore.Razor.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", 
    "Microsoft.AspNetCore.StaticFiles": "1.0.0", 
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0", 
    "Microsoft.EntityFrameworkCore.SqlServer.Design": { 
     "version": "1.0.0", 
     "type": "build" 
    }, 
    "Microsoft.EntityFrameworkCore.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 
    "Microsoft.Extensions.Configuration.Json": "1.0.0", 
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0", 
    "Microsoft.Extensions.Logging": "1.0.0", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0", 
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", 
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0", 
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    }, 
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { 
     "version": "1.0.0-preview2-final", 
     "type": "build" 
    } 
    }, 

    "tools": { 
    "BundlerMinifier.Core": "2.0.238", 
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final", 
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final", 
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final", 
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final", 
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { 
     "version": "1.0.0-preview2-final", 
     "imports": [ 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": [ 
     "dotnet5.6", 
     "portable-net45+win8" 
     ] 
    } 
    }, 

    "buildOptions": { 
    "emitEntryPoint": true, 
    "preserveCompilationContext": true 
    }, 

    "runtimeOptions": { 
    "configProperties": { 
     "System.GC.Server": true 
    } 
    }, 

    "publishOptions": { 
    "include": [ 
     "wwwroot", 
     "Views", 
     "Areas/**/Views", 
     "appsettings.json", 
     "web.config" 
    ] 
    }, 

    "scripts": { 
    "prepublish": [ "bower install", "dotnet bundle" ], 
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] 
    } 
} 

謝謝

+0

添加'project.json'文件的內容,請 – Dmitry

+0

這不要緊,我tryed新的項目,但它不工作...我會加 –

+0

嗯,你有很多EntityFrameworkCore包。 ..我少了。嘗試刪除除3之外的所有內容(2個依賴關係和一個工具) - 請參閱http://stackoverflow.com/documentation/entity-framework-core/3796/introduction-to-entity-framework-core/13132/adding-packages -項目 。我用我自己的項目作爲源。如果這不會幫助 - 創建小項目,並把github/bitbucket/... – Dmitry

回答

4

包管理器控制檯不支持 「全局命令」 呢。它只能在項目文件夾(包含project.json的文件夾)中理解「dotnet-ef」。

所以,你可以嘗試以下操作之一:

  1. 嘗試改變PMC的當前目錄到 project.json所在的文件夾。 (默認情況下,它指向解決方案的根目錄 文件夾,而不是項目。)

  2. 使用powershell運行該命令。

+0

非常感謝你這是我的回答:) –

+0

我得到的消息'dotnet:沒有可執行文件找到匹配命令「dotnet-ef」'無關緊要什麼。 –

+0

您是否安裝了dotnet cli?請嘗試遵循https://docs.asp.net/en/latest/tutorials/first-mvc-app/adding-model.html以確保您具備所有先決條件。 – Jack

相關問題