- Visual Studio For Mac Review
- Visual Studio On A Mac
- Visual Studio For Mac Clear Credentials
- Microsoft Visual Studio For Mac
- X Code
Visual Studio The powerful and flexible environment for developing applications in the cloud Visual Studio Code A powerful, lightweight code editor for cloud development SDKs Get the SDKs and command-line tools you need. In a blog post on November 16th 2015 Microsoft announced PowerShell support in Visual Studio Code.And as it befits the “new” Microsoft, this PowerShell extension for Visual Studio Code (VSC) was placed on GitHub. VSC offers features that are currently not present in the PowerShell ISE, one of the more important ones for now being Git support. Also, since my native machine is a Mac and.NET Core runs on a Mac and there is now Visual Studio for Mac Preview this is a great time to try to get a.NET app using the Angular CLI up and running.
Visual Studio Code has a powerful command line interface that lets you control how you launch the editor. You can open files, install extensions, change the display language, and output diagnostics through command-line options (switches).
If you are looking for how to run command-line tools inside VS Code, see the Integrated Terminal.
Launching from command line
You can launch VS Code from the command line to quickly open a file, folder, or project. Typically, you open VS Code within the context of a folder. To do this, from an open terminal or command prompt, navigate to your project folder and type code .
:
Note: Users on macOS must first run a command (Shell Command: Install 'code' command in PATH) to add VS Code executable to the PATH
environment variable. Read the macOS setup guide for help.
Windows and Linux installations should add the VS Code binaries location to your system path. If this isn't the case, you can manually add the location to the Path
environment variable ($PATH
on Linux). For example, on Windows, VS Code is installed under AppDataLocalProgramsMicrosoft VS Codebin
. To review platform specific setup instructions, see Setup.
Insiders: If you are using the VS Code Insiders preview, you launch your Insiders build with code-insiders
.
Core CLI options
Here are optional arguments you can use when starting VS Code at the command line via code
:
Argument | Description |
---|---|
-h or --help | Print usage |
-v or --version | Print VS Code version (for example, 1.22.2), GitHub commit id, and architecture (for example, x64). |
-n or --new-window | Opens a new session of VS Code instead of restoring the previous session (default). |
-r or --reuse-window | Forces opening a file or folder in the last active window. |
-g or --goto | When used with file:line[:character], opens a file at a specific line and optional character position. This argument is provided since some operating systems permit : in a file name. |
-d or --diff | Open a file difference editor. Requires two file paths as arguments. |
-w or --wait | Wait for the files to be closed before returning. |
--locale <locale> | Set the display language (locale) for the VS Code session. (for example, en-US or zh-TW ) |
Opening Files and Folders
Sometimes you will want to open or create a file. If the specified file does not exist, VS Code will create them for you along with any new intermediate folders:
For both files and folders, you can use absolute or relative paths. Relative paths are relative to the current directory of the command prompt where you run code
.
If you specify more than one file at the command line, VS Code will open only a single instance.
If you specify more than one folder at the command line, VS Code will create a Multi-root Workspace including each folder.
Argument | Description |
---|---|
file | Name of a file to open. If the file doesn't exist, it will be created and marked as edited. You can specify multiple files by separating each file name with a space. |
file:line[:character] | Used with the -g argument. Name of a file to open at the specified line and optional character position. You can specify multiple files in this manner, but you must use the -g argument (once) before using the file:line[:character] specifier. |
folder | Name of a folder to open. You can specify multiple folders and a new Multi-root Workspace is created. |
Working with extensions
You can install and manage VS Code extensions from the command line.
Argument | Description |
---|---|
--install-extension <ext> | Install an extension. Provide the full extension name publisher.extension as an argument. Use --force argument to avoid prompts. |
--uninstall-extension <ext> | Uninstall an extension. Provide the full extension name publisher.extension as an argument. |
--disable-extensions | Disable all installed extensions. Extensions will still be visible in the Disabled section of the Extensions view but they will never be activated. |
--list-extensions | List the installed extensions. |
--show-versions | Show versions of installed extensions, when using --list-extensions |
--enable-proposed-api <ext> | Enables proposed api features for an extension. Provide the full extension name publisher.extension as an argument. |
Advanced CLI options
There are several CLI options that help with reproducing errors and advanced setup.
Argument | Description |
---|---|
--extensions-dir <dir> | Set the root path for extensions. |
--user-data-dir <dir> | Specifies the directory that user data is kept in, useful when running as root. |
-s, --status | Print process usage and diagnostics information. |
-p, --performance | Start with the Developer: Startup Performance command enabled. |
--disable-gpu | Disable GPU hardware acceleration. |
--verbose | Print verbose output (implies --wait ). |
--prof-startup | Run CPU profiler during startup. |
--upload-logs | Uploads logs from current session to a secure endpoint. |
Multi-root | |
--add <dir> | Add folder(s) to the last active window for a multi-root workspace. |
Opening VS Code with URLs
On Windows and macOS, you can also open projects and files using the platform's URL handling mechanism. Use the following URL formats to:
Open a project
Open a file
Open a file to line and column
You can use the URL in applications such as browsers or file explorers that can parse and redirect the URL. For example, on Windows, you could pass a vscode://
URL directly to the Windows Explorer or to the command line as start vscode://{full path to file}
.
Next steps
Read on to find out about:
- Integrated Terminal - Run command-line tools from inside VS Code.
- Basic Editing - Learn the basics of the VS Code editor.
- Code Navigation - VS Code lets you quickly understand and move through your source code.
Common questions
'code' is not recognized as an internal or external command
Your OS can not find the VS Code binary code
on its path. The VS Code Windows and Linux installations should have installed VS Code on your path. Try uninstalling and reinstalling VS Code. If code
is still not found, consult the platform specific setup topics for Windows and Linux.
On macOS, you need to manually run the Shell Command: Install 'code' command in PATH command (available through the Command Palette⇧⌘P (Windows, Linux Ctrl+Shift+P)). Consult the macOS specific setup topic for details.
Visual Studio For Mac Review
How do I get access to a command line (terminal) from within VS Code?
VS Code has an Integrated Terminal where you can run command-line tools from within VS Code.
Can I specify the settings location for VS Code in order to have a portable version?
Not directly through the command line, but VS Code has a Portable Mode which lets you keep settings and data in the same location as your installation, for example, on a USB drive.
Recently I’ve been thinking about different ways to work Azure Functions, and the pros and cons of each. I wanted to better understand the Azure Functions Core Tools (also known as the CLI), and that role that plays in developing functions locally and then publishing them to Azure. I’d recently seen a Microsoft guy use this in his demos, and I was wondering if I was missing an important aspect of Azure Functions (which I try to stay on top of). Between Visual Studio Code/full Visual Studio/the command-line approach with the Core Tools, there’s a lot of overlap – so which is best when?
Azure Functions v2:
OK, back to the development options. First let’s be clear on what the process looks like with each.
Option 1 - with Azure Functions Core Tools/CLI
The command-line approach can be interesting because it’s the same across platforms, although to be fair it’s currently only version 2 of Azure Functions which can be used across macOS and Linux. But what you get here is the ability to:
- Create your function
- Run it locally
- Deploy to a Function App in Azure
PRE-REQS:
- Ensure you have .NET and node.js installed on your machine (for npm)
- Install Azure Functions Core Tools using npm install -g azure-functions-core-tools@core
- See Install the Azure Functions Core Tools for more info
PROCESS:
We’ll create a simple HTTP function in JavaScript in this case. As you might expect, we run commands at the command-line to create new functions and work with them.
- Create a folder for the function you’ll create, and open a command prompt there.
- Type func init to initalize the folder with the files needed for an Azure Function:
- To create a function, type funcnew to start the process. In V1 functions, you’ll need to provide:
- The language
- The trigger
- Provide a name for your function:
- Now open the function folder in VS Code (you do know about the “code .” command to open to the current directory right?):
- <VS Code opens>
- If you have the VS Code extension for Azure Functions installed, you’ll see this:
This is basically asking you if you’d like to switch to the VS Code way of doing things. For now, we’ll close this message to work with the command-line/Core Tools experience. - Now you can add code to your function as needed.
- Now type func run <Your function name> to run the function locally –the first time you do this, you’ll see this message that we need to OK:
- In the case of a HTTP function like this, we should pass some content in the POST body using the --content flag. To match up with the default code that the generator added, let’s pass some JSON including a ‘name’ attribute:
- You should now see the functions runtime spin up and serve your function:
- Since your function is being served on a local endpoint, you’ll most likely want to use Postman or similar as you develop the code (as per the earlier recommendation) since this is much richer than the --content flag. The output from the Core Tools will tell you the URL to hit, but by default it is http://localhost:7071/api/[function name]:
Publishing the (JavaScript) function using the CLI and Visual Studio Code
After developing the code some more, we can deploy directly to a Function App in Azure with other commands. Most likely you’ll need to login first, and this is done with the following command:
func azure login --username [username] --password [password]
If you don’t provide a username/password, you’ll be prompted interactively:
You may need to explicitly choose the Azure subscription (once you’ve signed-in) with this command, for example if that account has access to multiple subscriptions:
func azure account set [AzureSubscriptionID]
From here you can use the following to deploy the function:
func azure functionapp publish <FunctionAppName>
This is great, but something is missing – debugging!
Debugging the (JavaScript) function using the CLI and Visual Studio Code
At first I thought it wasn’t possible to debug functions locally using the CLI, but it is by combining it with VS Code. The process is:
- Put a breakpoint in your code in VS Code
- Run your function from the CLI and add the --debug flag – so func run <Your function name> –debug
- Hit F5 (or go to the Debug tab and press Play)
- Make a request to your function’s local URL e.g. http://localhost:7071/api/[function name]:
- Your breakpoint will now be hit and you can make use of all of VS Code’s debugging capabilities:
- DevOps scenarios, where you have some automation scripts to run/test your functions (either locally or by deploying them up to Azure)
- You're trying to be ultra-hip
Option 2 – with Visual Studio Code
PRE-REQS:
- You’ll need the Azure Functions VS Code extension. This can be obtained from https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions. It looks like this when installed:
PROCESS:
Creating a function in VS Code is easy:
- First, create a folder on your machine to host the files – I named my folder “COB-JS-Functions” to reflect what we’re doing here.
- Open VS Code to this folder.
- Hit CTRL SHIFT + P for the VS Code command bar, and start typing “Azure Functions” to pull up those commands. Select the “Create New Project” command:
- Follow the prompts in the command bar to select the folder – accept the default if you’re already in the folder you created earlier:
- When it comes to selecting a language, select your preference – I’m using JavaScript here (and you might want to consider my overall message that C# functions are generally easier in full-blown Visual Studio!):
- Your folder will now be scaffolded with the starter files:
- Now let’s add an individual function. Hit CTRL SHIFT + P again, and find the “Create Function” command under Azure Functions:
- Accept that we’ll use the current folder:
- Select the trigger:
- Enter the name for your function:
- And then the authentication type:
- A bunch of new files will now be added to your folder, including the “index.js” file for your function implementation:
You can now code away and start to build out your function. Most likely you’ll want to bring in some npm modules for a JavaScript function, and start to work against the Graph, SharePoint or whatever you need. I really like being guided through the process through the VS Code command palette, I think it works really well.
Debugging Azure Functions locally in Visual Studio Code
VS Code works great as a debugger for JavaScript functions, PowerShell scripts and more. The next sections have a couple of notes on language-specific details:
For JavaScript Functions
JavaScript mainly “just works”, although you’ll need to hit the local URL your function is hosted on (e.g. with Postman or similar) by default. You can go a step further and amend your launch.json file so that F5 does everything - I had to add a configuration for ‘launch’ as well as ‘attach’. The process looks like this:
Visual Studio On A Mac
- Add a breakpoint to your code.
- Once your launch.json is good, ensure you have a “launch” configuration selected in the debug config selector – this ensures node.js is started, rather than assuming it’s running already and you can attach to it:
- You should see VS Code spin up the functions host for you by running func host start:
- You’ll actually need to hit the URL for your function to start the execution and hit your breakpoint. VS Code makes this easy by providing a clickable link in the terminal output:
- This will open a new browser tab, hit your function endpoint, and your breakpoint will be hit
For PowerShell Functions
See my “Running a PowerShell script in the cloud with an Azure Function, PnP and the Graph” article, specifically the “Debugging our PowerShell script locally with F5” section – I show the process in detail here. In short it works well, but remember that PowerShell only has experimental language status in Functions V1, and this did not go forward into V2.
For C# Functions
Well, debugging C# functions which are .cs files (not .csx) in Visual Studio Code is somewhat different – the OmniSharp extension is required (https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp) and there is some shennanigans involved to debug V1 functions since they are 32-bit. See https://github.com/Microsoft/vscode-azurefunctions/blob/master/docs/func64bit.md. Overall I feel that full Visual Studio is a simpler approach for C# functions.
Publishing files to an Azure Function from VS Code:
Visual Studio For Mac Clear Credentials
In the spirit of re-use, this section comes straight from my PowerShell functions article :) The steps here are the same regardless of your function language.
You can publish your function to Azure in a variety of ways, but VS Code makes this easy:
- Switch to Azure tab in VS Code (bottom icon):
- Find the Function App you created earlier. Right-click on it, and select “Deploy to Function App”:
- Step through prompts in the VS Code command palette – the defaults are generally what you need:
- Accept the prompt:
- VS Code will then start the publish operation:
- You’ll then find that your files have been deployed as a Function to the selected Function App:
Option 3 – using Visual Studio
Visual Studio is my preferred option for C# functions (for the moment at least).
PRE-REQS:
- Ensure you have the Azure Functions Visual Studio extension installed – this comes bundled into the Azure development workload of Visual Studio 2017 or can be obtained from https://marketplace.visualstudio.com/items?itemName=VisualStudioWebandAzureTools.AzureFunctionsandWebJobsTools. It looks like this when installed (in Tools and Extensions):
See https://docs.microsoft.com/en-us/azure/azure-functions/functions-develop-vs for more details.
PROCESS:
There is a VS project template, so creating a new project is easy:
- Create a new project using Create > New Project:
- Add a new Function from the context menu on the project:
Select the trigger type:
Debugging a function in Visual Studio:
This is as simple as adding a breakpoint and hitting F5. For C# functions, as things stand this is much simpler than the other options. You’ll see the Core Tools function host spin-up, and the URL of your function will be provided – you’ll need to hit this in a browser or with Postman, although you could configure the “Debug” tab of your project to launch a browser or script to do this automatically (similar to the idea of editing the launch.json file if using Visual Studio Code):
Your breakpoint will then be hit:
Microsoft Visual Studio For Mac
Remember that you can also debug a function running live in Azure if it was published in debug mode. If you’re developing against a dev/test Office 365 tenant and Azure subscription this can be very helpful (but not recommended for production obviously). Use the Cloud Explorer to find your function, right-click and select “Debug”.
X Code
Publishing a function from Visual Studio
Anyone who’s worked with functions in VS is probably familiar with this, but as you’d expect it’s a slick experience:
But as the saying goes, friends don’t let friends publish Azure Functions directly to production (and potentially other environments too). Use one of the other deployment methods, perhaps one based on continuous deployment if appropriate.
Summary
That was quite a lot detail. In summary, if you write the majority of your other code with VS Code and/or are writing functions in JavaScript, then VS Code is probably your best choice – just make sure you install the Azure Functions VS Code extension. If you’re mainly using full Visual Studio, then stick with that for functions development too – just make sure you install the Azure Functions Visual Studio extension if your VS instance doesn’t have it already.
Using the Core Tools directly from the command-line is best-suited to CI/CD/DevOps automation, or those who feel the need to be particularly hipster.