45

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?

Ivan
  • 63,011
  • 101
  • 250
  • 382
  • Launch one of the Developer Command Prompts that got installed alongside Visual Studio. It is preconfigured so that you don't have to fumble with settings. For reference, *dotnet.exe* is installed in `%ProgramFiles%\dotnet` on my system. – IInspectable Mar 03 '17 at 22:10

9 Answers9

46

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:

  1. Open control panel>System and Security>System

  2. Click on Advanced system settings

  3. In advanced section, click in Environment Variables

  4. In System variables, select path and edit

  5. In Windows 7 After semicolon, write "C:\Program Files\dotnet"

    In Windows 10 or 11, Click New and write "C:\Program Files\dotnet"

  6. 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.

Manish Jain
  • 1,197
  • 1
  • 11
  • 32
  • This was the solution after uninstalling old versions of the SDK – JGH Feb 03 '20 at 17:26
  • Works! but for Windows 10, the `Advanced system settings` seems to be missing (?). Type in the search box `env` and then click on one of the results. Doesn't seem to be any semicolons either, but just add the path on the next blank line. – Jim Dec 31 '22 at 17:09
11

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
Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
10

I've just found the answer myself. It seems like the dotnettool 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)

Community
  • 1
  • 1
Ivan
  • 63,011
  • 101
  • 250
  • 382
3

I have the same issue on windows 10 64bit after installing dotnet core SDK 3.1 To resolve it, I defined the environnement variables path for .netcore 3.1 and restarted my machine. enter image description here

MNF
  • 687
  • 9
  • 13
2

Download and install .NET core from https://dotnet.microsoft.com/download/dotnet-core, open a new prompt once it's installed.

dotnet

You will get the following message if installation is successful. The path where dotnet.exe is will be added to PATH as part of the installation.

Usage: dotnet [options]
Usage: dotnet [path-to-application]

Options:
  -h|--help         Display help.
  --info            Display .NET Core information.
  --list-sdks       Display the installed SDKs.
  --list-runtimes   Display the installed runtimes.

path-to-application:
  The path to an application .dll file to execute.
Jonathan Chow
  • 1,207
  • 1
  • 9
  • 11
1

To future readers

If on Windows check if you have multiple installations of dotnet on Program Files and Program Files (x86) or Program Files(x32). win + R open cmd, type

where.exe dotnet

only Program Files should have dotnet. Restart Visual Studio .

James G
  • 11
  • 1
0

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.

bricelam
  • 28,825
  • 9
  • 92
  • 117
-1

I had the following error in Visual Studio when first installed .net sdk. I finally just closed VS code, reopened VS Code, and it worked fine.

'dotnet' is not recognized as an internal or external command, operable program or batch file

-2

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

Jayani Sumudini
  • 1,409
  • 2
  • 22
  • 29