问题
I am exploring the new Entity Framework Core (NOT in conjunction with ASP.Net, what I am coding is just a WinForms app) and found some tutorials mentioning a dotnet
command line command needed to create "migrations". When I try it, however, it says 'dotnet' is not recognized as an internal or external command, operable program or batch file.
I have searched my hard drive for "dotnet.exe", "dotnet.bat" and "dotnet.cmd" but have found nothing. I use Visual Studio 2015 Community Edition. Where do I find this command executable? What am I to add to the %PATH%
environment variable for it to work?
回答1:
I've just found the answer myself. It seems like the dotnet
tool does not get installed with Visual Studio. Installing .NET Core tools preview for Visual Studio (direct link to the .NET Core 1.0.1 tools Preview 2: DotNetCore.1.0.1-VS2015Tools.Preview2.0.3.exe) resolved the problem by adding %ProgramFiles%\dotnet\dotnet.exe
.
I have faced another problem after this, however: the dotnet
tool running but saying No executable found matching command "dotnet-ef"
but this is a matter of another question. I will, however, share the solution here once I find it.
UPDATE:
As promised, here are the question and the answer about the thext problem I have faced (the No executable found matching command "dotnet-ef"
error).
And here is the solution for the next one (the ... violates the constraint of type 'TContext'
error)
回答2:
For me it is located at C:\Program Files\dotnet
You need to install .NET SDK separately. You can download and install from https://download.microsoft.com/download/1/1/5/115B762D-2B41-4AF3-9A63-92D9680B9409/dotnet-sdk-2.1.4-win-gs-x64.exe
More details : https://www.microsoft.com/net/learn/get-started/windows
Also I did not have to set up path variable. After running above installation dotnet was automatically added in path. Just open a new cmd and run -
C:\Users\anike>dotnet --version
2.1.4
回答3:
dotnet.exe is located in
C:\Program Files\dotnet>
If you are using command prompt and getting message that 'dotnet' is not recognized as an internal or external command, operable program or batch file" then first check the above path. If you found the above path then just copy it and set it as an environment variable of your PC.
Steps:
Open control panel>System and Security>System
Click on Advanced system settings
In advanced section, click in Environment Variables
In System variables, select path and edit
After semicolon, write "C:\Program Files\dotnet"
Click on Ok button till end.
now to check whether its working on not. Just open command propmpt and type
dotnet --version
This will show the dotnet version installed in your PC.
回答4:
For windows the reason was that it need to run from a Command prompt outside from visual studio. execute this command in command prompt,
dotnet run
then application run in https://localhost:5001
回答5:
If you're using .NET Framework 4.x and WinForms, you probably don't want to use the .NET Core tools (i.e. dotnet ef
). Instead, install the Microsoft.EntityFrameworkCore.Tools
package and use the NuGet Package Manager Console (or PMC) PowerShell cmdlets: Add-Migration
, Update-Database
, etc.
来源:https://stackoverflow.com/questions/42588392/where-is-the-dotnet-command-executable-located-on-windows