42

The majority of .NET core tutorials online seem to use Visual Studio code, rather than Visual Studio (Full fat? Is there a proper term for the full version? I use Professional but there is also Community, Enterprise etc).

These tutorials make the most of the integrated terminal within VS code for running dotnet command line commands (dotnet new, dotnet build etc).

I am struggling to find where to execute these commands in Visual Studio. Where is the right place to do this? I have .NET core SDK installed.

I have seen some suggestions for the package manager console - although this seems odd, why should I be running dotnet commands via a "package manager console"?

4
  • Visual Studio typically has .NET Core templates built in, but you can execute commands in the command line Commented Jun 20, 2018 at 13:00
  • 1
    @James_Parsons that doesn't answer the question. Does visual studio offer an integrated command line I can use? I realise a lot of the dotnet commands relate to actions you can perform using the UI in Visual Studio. However when following tutorials etc it is much easier to follow using the same method. Commented Jun 20, 2018 at 13:04
  • You are correct: it does not answer the question. Hence why it was written as a comment and not an answer. And although you never asked it in your question, no, by default Visual Studio does not ship with an integrated terminal. You can enter the commands in a separate command line as I noted, or find an add-in for VS that adds an integrated terminal. Commented Jun 20, 2018 at 13:07
  • 2
    not sure why this was voted down. .NET Core has indeed made things confusing for developers on Windows, where VS has traditionally been the "end all, be all" for .NET development. in fact, it's odd to me that VS doesn't have all the functionality of the dotnet binary. Commented Jun 27, 2018 at 7:39

6 Answers 6

27

Update: Visual Studio 2019 16.6 now has it's own Terminal (Hoorray!). Check View -> Terminal or try to press Ctrl + `.

Old answer:

There are extensions for that. I tried BuiltinCmd and Whack Whack Terminal, the latter worked better for me. You can choose between CMD and PowerShell, all dotnet CLI commands works just fine. Whack Whack terminal screenshot with dotnet watch run

Sign up to request clarification or add additional context in comments.

Comments

20
  1. The full version of Visual Studio is "Visual Studio", "Code" is what differentiates "Visual Studio Code".

  2. As far as an integrated command line inside Visual Studio goes, the Package Manager Console is it. It's basically just powershell, with some addins from Visual Studio and any extensions or NuGet packages you have installed. It gets its name from the fact that it was introduced specifically for the management of NuGet packages, but was quickly co-opted by things like Entity Framework, and just continued to grow from there. Admittedly, Microsoft should probably consider rebranding it, but there's so much documentation, articles and tutorials out there that reference the "Package Manager Console", that it would probably actually create more confusion if they renamed it.

  3. While you can run dotnet commands through it, I'd imagine the results would be a bit unpredictable. Perhaps I'm wrong here, as I've never even tried to do things like dotnet new from the PMC, but the PMC is not really directory-based like a traditional console window. It's more contextual in nature, applying commands to target projects. I do know that things like dotnet restore and such work fine, and dotnet new may as well. You'll just have to try it.

That said, I tend to take an all or nothing approach with Visual Studio. It's a beast, and if you're going to install it and use it, you might as well use it. You can do everything you can do with dotnet through the GUI. And, for those few times where you might need something special, you can pop a console window. If you want to do everything with dotnet, Visual Studio quickly becomes overkill, and Visual Studio Code would probably be much more efficient for your workflow.

3 Comments

Thank you very much. Regarding 1) I guess was a pretty ignorant question that was fuelled mainly by frustrations of trying to google tutorials for visual studio but receiving all results for visual studio code, I guess you can use "visual studio -code" when searching but that may remove some meaningful results. 2) perfect explanation and mainly clarified what I assumed 3) This is exactly the info I was missing! thank you! the concept of the package manager console not running in a directory-based context. Thank you again!
Also to clarify why I was wanting this functionality: I wanted to create a .NET core NUnit project in my solution. All of the tutorials use the "dotnet new nunit3" command line, and as there is no equivalent project file to select when going through the UI. I found out that there is no nice equivalent in Visual Studio, you need to create a .NET Core class library then manually pull in the dependencies.
As far a Googling goes, you can try "Visual Studio" -"Visual Studio Code". That should return only results that mention Visual Studio, while excluding results that mention Visual Studio Code.
8

While following a tutorial to update database, I had to run these commands

dotnet ef migrations add MaxLengthOnNames dotnet ef database update

in the command window of Visual studio, as per tutorial. When I opened this window in visual studio (View > Other Windows > Command Window) and attempted to run these commands, I received this error:

>dotnet ef migrations add MaxLengthOnNames Command "dotnet" is not valid. >dotnet ef database update Command "dotnet" is not valid. > 

When I attempted to run them in Package Manager Console, this is the result I got:

No project was found. Change the current working directory or use the --project option.

Now, I googled it a bit and got the hint that I must run these commands in windows command prompt (opened by typing "cmd" in Windows start search). Steps are:

  • Open windows command prompt
  • Set your project directory as current directory
  • run any dotnet command you need like I entered this: dotnet ef database update
  • success

1 Comment

I had to add "C:\Program Files\dotnet" to my PATH environment variables to let it find dotnet.exe, but after this, it now works as stated here.
5

I'm not sure what version of Visual Studio it was added, but Tools ... Command Line ... Developer Command Prompt will open a command prompt for you at your solution's root. From there, cd into the project you want to run and then dotnet run.

Also, if your version of Visual Studio doesn't have that menu option preinstalled, you can add it as an "External Tool" pretty easily: link

2 Comments

The same menu in Visual Studio 2019 Tools -> Command Line -> now has Developer Powershell which opens the Powershell terminal in the solution directory. The only missing feature compared to VSCode or Package Manager Console is that it is not a tool window that can be docked.
This answer saved me from installing and depending on third-party extensions like ConEmu or Whack Whack Terminal. This option is light, simple and already available with VS. You just need to know how to go about with it. Thanks for that "External Tool" link.
4

Tools -> Command Line -> Developer Powershell

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

You can execute cmdlets in the Visual Studio Package Manager Console that are functionally equivalent to at least some of the dotnet commands.

For example, there is a suite of cmdlets you can call that are equivalent to the dotnet ef commands. See here: https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell

So the equivalent of dotnet ef migrations add MaxLengthOnNames in the Package Manager Console is Add-Migration MaxLengthOnNames.

And the equivalent of dotnet ef database update in the Package Manager Console is Update-Database.

Using that page I linked to it should be fairly easy to figure out the cmdlet equivalents of the remaining dotnet ef commands.

I don't know about dotnet run though.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.