Visual Studio For Mac Terminal



Question or issue on macOS:

I’d like to run / open Visual Studio Code from the Mac OSX Terminal by running this command code .. I found instructions here:

How to do it To open Visual Studio Code from your command line, you need to make sure that you have the VS Code command line tools installed. On Windows, this should work out of the box. On Mac, open up VS Code, go to View - Command Palette and search for this. Visual Studio Code on macOS Installation. Download Visual Studio Code for macOS. Open the browser's download list and locate the downloaded archive. Select the 'magnifying glass' icon to open the archive in Finder. Drag Visual Studio Code.app to the Applications folder, making it available in the macOS Launchpad. By terminal, do you mean 1) Command Line on Windows? 2) Terminal on Mac 3) Terminal on Linux 4) As a default GIT editor on Windows 5) As a default GIT editor on Mac 6) As a default GIT editor on Linux For #1 Running Visual Studio Code on Windows I.

https://code.visualstudio.com/Docs/setup

Apparently I need to include this in my .bashrc file, so I did, but to no avail.

I edited the .bashrc file here:

~/.bashrc which points to /Users/username/.bashrc

Which .bashrc should I be editing?

How to solve this problem?

Solution no. 1:

Try this one

Open Visual Studio Code and press Command + Shift + P or F1 then type Shell in command palette now you are able to find this option like Shell Command : Install code in PATH from suggested list in command palette. Select that options.

That’s it.

Now open your terminal type.

Solution no. 2:

I just want to pull out Benjamin Pasero’s answer from inside his comment as it seems the best solution. It is the tip given on the Setting up Visual Studio Code page where it says …

If you want to run VS Code from the terminal, append the following to your ~/.bash_profile file (~/.zshrc in case you use zsh).

Now, you can simply type code . in any folder to start editing files in that folder. [Or code test.txt to go to work on the test.txt file]

Solution no. 3:

If you are on Mac OSX Maverick,
it’s ~/.bash_profile not ~/.bashrc

Try putting the code in there, close the terminal and then try again. Should be working

Solution no. 4:

For Mac you can do :
View > Command Palette > Shell command > “install code command in path”. I’d assume there would be something similar for other OS’s. After I do

and it tells me it put it in /usr/local/bin

Solution no. 5:

Sometimes, just adding the shell command doesn’t work. We need to check whether visual studio code is available in “Applications” folder or not. That was the case for me.

Visual Studio Community For Mac

The moment you download VS code, it stays in “Downloads” folder and terminal doesn’t pick up from there. So, I manually moved my VS code to “Applications” folder to access from Terminal.

Step 1: Download VS code, which will give a zipped folder.

Step 2: Run it, which will give a exe kinda file in downloads folder.

Step 3: Move it to “Applications” folder manually.

Step 4: Open VS code, “Command+Shift+P” and run the shell command.

Step 5: Restart the terminal.

Step 6: Typing “Code .” on terminal should work now.

Solution no. 6:

For Mac users:

One thing that made the accepted answer not work for me is that I didn’t drag the vs code package into the applications folder

Visual Studio For Mac

So you need to drag it to the applications folder then you run the command inside vs code (shown below) as per the official document

  • Launch VS Code.
  • Open the Command Palette (⇧⌘P) and type ‘shell command’ to find the
    Shell Command: Install ‘code’ command in PATH command.

Solution no. 7:

To set up VS code path permanently on Mac OS;

just open .bash_profile using the following command on terminal

Then add the following path to .bash_profile

save the .bash_profile file and quit the terminal. Then reopen the terminal and type code .to open VS code.

Solution no. 8:

Visual Studio For Mac Terminal

How about a simple Bash alias that you stick in your .bash_profile ?


alias code=”open -a /Applications/Visual Studio Code.app”

To open the current directory:


code .

Solution no. 9:

To set it up, launch VS Code. Then open the Command Palette (⇧⌘P) and type shell command to find the Shell Command: Install ‘code’ command in PATH command.enter image description here

Solution no. 10:

I simply created a file called code:

Make it executable:

Then put that in /usr/local/bin

As long as the file sits someplace that is in your path you can open a file by just typing: code

Hope this helps!

-->For

This tutorial shows how to create and run a .NET console application using Visual Studio for Mac.

Note

Your feedback is highly valued. There are two ways you can provide feedback to the development team on Visual Studio for Mac:

  • In Visual Studio for Mac, select Help > Report a Problem from the menu or Report a Problem from the Welcome screen, which will open a window for filing a bug report. You can track your feedback in the Developer Community portal.
  • To make a suggestion, select Help > Provide a Suggestion from the menu or Provide a Suggestion from the Welcome screen, which will take you to the Visual Studio for Mac Developer Community webpage.

Prerequisites

  • Visual Studio for Mac version 8.8 or later. Select the option to install .NET Core. Installing Xamarin is optional for .NET development. For more information, see the following resources:

    • Tutorial: Install Visual Studio for Mac.
    • Supported macOS versions.
    • .NET versions supported by Visual Studio for Mac.

Create the app

  1. Start Visual Studio for Mac.

  2. Select New in the start window.

  3. In the New Project dialog, select App under the Web and Console node. Select the Console Application template, and select Next.

  4. In the Target Framework drop-down of the Configure your new Console Application dialog, select .NET 5.0, and select Next.

  5. Type 'HelloWorld' for the Project Name, and select Create.

The template creates a simple 'Hello World' application. It calls the Console.WriteLine(String) method to display 'Hello World!' in the terminal window.

Visual Studio For Mac Os

The template code defines a class, Program, with a single method, Main, that takes a String array as an argument:

Main is the application entry point, the method that's called automatically by the runtime when it launches the application. Any command-line arguments supplied when the application is launched are available in the args array.

Run the app

  1. Press (option+command+enter) to run the app without debugging.

  2. Close the Terminal window.

Enhance the app

Enhance the application to prompt the user for their name and display it along with the date and time.

  1. In Program.cs, replace the contents of the Main method, which is the line that calls Console.WriteLine, with the following code:

    This code displays a prompt in the console window and waits until the user enters a string followed by the enter key. It stores this string in a variable named name. It also retrieves the value of the DateTime.Now property, which contains the current local time, and assigns it to a variable named date. And it displays these values in the console window. Finally, it displays a prompt in the console window and calls the Console.ReadKey(Boolean) method to wait for user input.

    NewLine is a platform-independent and language-independent way to represent a line break. Alternatives are n in C# and vbCrLf in Visual Basic.

    The dollar sign ($) in front of a string lets you put expressions such as variable names in curly braces in the string. The expression value is inserted into the string in place of the expression. This syntax is referred to as interpolated strings.

  2. Press (option+command+enter) to run the app.

  3. Respond to the prompt by entering a name and pressing enter.

  4. Close the terminal.

Next steps

In this tutorial, you created a .NET console application. In the next tutorial, you debug the app.