Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running dotnet command line within Visual Studio

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"?

like image 400
AndyNZ Avatar asked Jun 20 '18 12:06

AndyNZ


People also ask

How do I access .NET CLI in Visual Studio?

You can run the generated C# code projects with Visual Studio by pressing the F5 key or with dotnet run (. NET CLI).

How do I run a .NET core console app from the command line?

In . NET Core, it runs from the dll, so you have to just run the application by running the command prompt and using the command - dotnet run. Open your command prompt and go to that folder where your application persists.


3 Answers

  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.

like image 145
Chris Pratt Avatar answered Oct 08 '22 18:10

Chris Pratt


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

like image 25
Lev Avatar answered Oct 08 '22 20:10

Lev


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
like image 7
Saima Avatar answered Oct 08 '22 19:10

Saima