Parse and use visual Studio code to compile and debug C # program "Go" on Mac

Source: Internet
Author: User

0x00 Preface

A week or so ago Microsoft's Build conference, Microsoft released a lot of people in front of the tool, is also the protagonist of this article--visual Studio Code. Many friends who use windows are happy to think that there is a good document editor. But Bastard is more concerned about its cross-platform capabilities, this is not, bastard stole half-day, writing a small article to talk about how to use Visual Studio code to compile and debug C # code on a Mac, and finally bastard will try to embed Visual Studio code in Unity3d, Used as a quasi-"IDE".

0x01 Visual Studio code is who?

Well, since we're going to talk about visual Studio Code, we always have to know where it's sacred, right?

People who are interested in Microsoft or Microsoft Build Conference news, believe that it must be a stranger. Excerpts from a few of the news at the time, you can have a more intuitive impression.

News excerpt One:

During the build conference, Microsoft released the new app--visual Studio Code in the Visual Studio developer tools. Microsoft describes Visual Studio code as the "Coding optimization Editor", which is available for download to all developers free of charge and offers Mac OS and Linux versions.

News Excerpt Two:

First of all, this Visual Studio code (hereinafter referred to as Vscode) is an editor with a GUI, which can only complete simple code editing functions, not an integrated development environment (IDE)

So don't know if you and bastard first heard the news when the same feeling, is Microsoft suddenly released such a tool? Not only does it cross the platform but it also seems to be different from the traditional Visual Studio.

Yes, Visual Studio code is actually born out of an open source framework--electron that uses javascript,html and CSS and is based on io.js and chromium GitHub. And a lot of people familiar with the open source Code Editor--atom editor (in order to represent the difference, not to be confused with the following Atom Shell, as long as the atom is the editor, then use the Atom Editor as the name) also used the Elctron framework, Bastard heard before that the visual Studio code is based on the Atom editor, which is not accurate, but they all use electron. And by unlocking the contents of visual Studio code, you can see that there are many files that are named "Atom," and what is this? In fact, to the host page of electron can see the answer, the electron before the name of the Atom shell, and visual Studio code atom refers to the atom Shell is actually (by the way, before Microsoft has the visual Studio Online, the editor called Monaco).

While the Atom editor is also based on Elctron, no one will confuse the visual Studio code with the Atom editor because Microsoft has apparently added some of its own features, such as Roslyn and another " Open source projects that enable developers to get a good C # development experience in any editor on any platform Omnisharp also joined in.

Let's take a look at the contents of the Mac version of Visual Studio code.

We can clearly see that visual Studio code uses the Atom Shell framework.

0x02 yourself, clothed

Well, now that we've solved the problem of who the visual Studio code is, let's go further. Continue to talk about visual Studio Code in the order that you install it from on your Mac, to custom features.

Install Visual Studio Code

Installing Visual Studio Code takes two steps, first installing ASP. NET 5, and then installing Visual Studio Code (in fact it doesn't matter in order, Bastard is the Visual Studio code that was installed first).

There are a lot of instructions on how to install ASP. NET 5 on your Mac. In fact, it is also very simple, direct use homebrew can.

    $ brew Tap aspnet/dnx    $ brew Update    $ brew Install DNVM

After that, it will be very easy to operate.

After installing Visual Studio Code, we need to go to the official website download the Mac version.

For more detailed installation instructions, refer to here.

Custom configuration Files

OK, after the installation is complete, we can finally start our Visual Studio Code First experience.

Since bastard is a common function of defining jumps, it is very sensitive to the shortcut keys for defining jumps. The Bastard Mac on the F12 default to the volume adjustment, many of the F12 as a definition Jump Editor bastard initially is very exclusive (duang~~~). However, the editor of Visual Studio Code obviously provides a convenient user-definable JSON configuration.

So bastard to find the JSON file that controls the accelerator configuration, bastard first displays the command for Visual Studio code using the shortcut key combination cmd+p.


Here are all the commands.

Then bastard only need to enter key to find the open KeyBoard shortcuts This command, execute it to open the default shortcut key configuration.

The left side is the default shortcut key setting, and the right side is the user-defined JSON file for the keyed settings. Here Bastard will define the jump set as a custom cmd+y combination.

Bastard This example, mainly to show that we can easily customize this editor. So the following bastard continue to talk to you, how to use Visual Studio code to open, compile, and debug a project on your Mac.

0x03 Open, compile, and debug a project

To demonstrate Visual Studio code's so-called cross-platform capabilities, bastard first generated a project on Windows, named ConsoleApplication2, which is used primarily to implement a self-introduction feature. The following bastard from open, compile and debug these three aspects to chat.

Start by showing the location and content of this project from Windows on your Mac:

Open a project

To compile this project, we obviously need to import the project in virtual Studio Code first.

We only need to select Open in the File drop-down menu:

The project is now imported into virtual Studio code.

Open the Programe.cs file, we can see the function of intelligent induction, auto-completion.

The project has already been imported, so the next step is to compile the project.

Compiling a project

At this point, we use the Cmd+p shortcut key combination again to display the command of Visual Studio code. This time we enter >configure task runner. Open the Tasks.json file to configure the task.

cmd+p>configure Task runner

Modify the default task to the following:

"version"0.1.0","command"xbuild","args": [" ConsoleApplication2.sln"]               

This project is compiled ConsoleApplication2.

Then use the Shift+cmd+b shortcut key to compile.


At this point we can see that an Output window appears to the right of the Visual Studio Code Editor, showing the contents of the compilation process.

Displays the compilation success. At the same time, we can see the ConsoleApplication2.exe file just generated in the project directory.

(written here, this is 0:11)

In this way, we use virtual Studio code to compile a project from Windows using Mono.

Sounds interesting, doesn't it? Then let's execute the generated program and try to debug it.

Debugging a Project

OK, people familiar with bastard routines must be here to know what bastard to do. Yes, this time, use the Cmd+p shortcut key combination to display the command for Visual Studio code. But this time the order was replaced by >debug:configure.


This time the Debug configuration JSON file--launch.json is paged out.

You can see that the default Launch.json is used to handle Nodejs, and the name is directly called "Launch app.js".

So we need to modify this configuration file to use Mono.

The following is bastard modified Launch.json.

Then we click the Run button in debug mode.

You can see the run to the breakpoint.

At this point, we open the breakpoint, and then go back to the terminal to see the output results.

OK, Bastard's name was printed out.

As you can see, virtual Studio Code is a lightweight, but also has a smart sensor, auto-completion, git management, compile and debug functions such as the editor. How can this make people not love?

0X04 integrated into Unity3d

Above said a lot, but bastard now after all to develop using UNITY3D development game mainly. So can you use virtual Studio code in Unity3d? (Of course, many students will say that virtual studio can not be integrated into the Unity3d via plugins?). But, after all, there are a lot of people using Mac to do development ... )

The answer is yes, but the import project is not the same as before. and first of all make it clear that virtual Studio code is not a true IDE, and the current version is 0.1.0, in other words, immature. So with Unity3d, bastard only do exploration, there is no subjective recommendation or not recommended.

Ensure that the mono version is high enough

Why did you say that first? It is well known that the mono version of Unity3d is still in its lower version several years ago. So many unity3d practitioners of the mono version are actually very low, and in order to be able to use the virtual Studio code, the official requirement is that mono version is more than 3.12. So in order to insure, or to upgrade mono to the latest version, of course you do not have to worry about Unity3d's own mono will be affected.

If you're just curious, there's no need to modify Unity's default editor

Of course, virtual Studio code can also act as the default editor for unity. But Bastard reminds, if only for the sake of curiosity, there is no need to make this change, because in the end you have to change back, more thankless thing.

Start integration

Open our Unity3d interface, open the Assets drop-down menu, and click Sync MonoDevelop Project.

Then import the project into virtual Studio Code, which is basically similar to the example above, but there are some differences.

You can see that the familiar Unity3d project directory already appears in virtual Studio code. However, the project is not actually imported, because Unity's project has 2 sln, one is the project name. SLN, and the other is the project name-csharp.sln. So virtual Studio code cannot be determined, which requires us to handle it manually. Click the bottom flame icon (project), which appears as a drop-down bar for selecting Project.

At this point we choose Egg-csharp.sln. Okay, so you can happily use virtual Studio code to write the codes.

0X05 Summary

Although virtual Studio code is still young, it may still have a lot of shortcomings, but don't forget the meaning of its appearance. From open source CoreCLR to the latest build conference, Microsoft's attitude and actions are really looking forward to.

Parse and use visual Studio code to compile and debug C # program "Go" on Mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.