Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing tip #1320

Merged
merged 8 commits into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 45 additions & 30 deletions docs/csharp/getting-started/with-visual-studio-code.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: Getting started with visual Studio Code | C# Guide
description: Getting Started with Visual Studio Code
title: Getting started with Visual Studio Code | C# Guide
description: Learn how to create and debug your first .NET Core application in C# using VS Code.
keywords: C#, Getting Started, Acquisition, Install, Visual Studio Code, Cross Platform
author: kendrahavens
ms.author: wiwagn
ms.date: 11/14/2016
ms.date: 12/09/2016
ms.topic: article
ms.prod: .net
ms.technology: devlang-csharp
Expand All @@ -16,64 +16,79 @@ ms.assetid: 76c23597-4cf9-467e-8a47-0c3703ce37e7

.NET Core gives you a fast and modular platform for creating server applications that run on Windows, Linux and macOS. Use Visual Studio Code with the C# extension to get a powerful editing experience with full support for C# IntelliSense (smart code completion) and debugging.

## Getting Started
## Prerequisites

1. Install [Visual Studio Code](https://code.visualstudio.com/).
2. Install [.NET Core](https://microsoft.com/net/core).
2. Install the [.NET Core SDK](https://www.microsoft.com/net/download/core).
3. Install the [C# extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.csharp) from the VS Code Marketplace.

## Hello World

If you'd like to get started with a simple "Hello World" program on .NET Core, follow the steps below:
Let's get started with a simple "Hello World" program on .NET Core:

1. Open a project:

* Open VS Code.
* Go to the File Explorer Tab on the left.
* Open the folder you want your C# project to be in.
* Click on the Explorer icon on the left menu and then click **Open Folder**.
* Select the folder you want your C# project to be in and click **Select Folder**.

![VSCodeOpenFolder](media/with-visual-studio-code/VSCodeOpenFolder.PNG)
![VSCodeOpenFolder](media/with-visual-studio-code/vscodeopenfolder.png)

* Alternatively, you can select **File** > **Open Folder** from the main menu to open your project folder.

2. Initialize a C# project:
* Open the command prompt (or terminal). You can open the terminal from VS Code by typing <kbd>CTRL</kbd>+<kbd>`</kbd> (Back Tick)
* Type `dotnet new`
* Open the Integrated Terminal from VS Code by typing <kbd>CTRL</kbd>+<kbd>`</kbd> (backtick).
* In the terminal window, type `dotnet new`.
* This creates a `Program.cs` file in your folder with a simple "Hello World" program already written.

![dotnetNew](media/with-visual-studio-code/dotnetNew.PNG)
![dotnet new command](media/with-visual-studio-code/dotnetnew.png)

3. Resolve the build assets by typing `dotnet restore`
3. Resolve the build assets:

* Running `restore` pulls down the required packages declared in the `project.json` file.
* Type `dotnet restore`. Running `dotnet restore` pulls down the required packages declared in the `project.json` file.
* You'll see a new `project.lock.json` file in your project folder.
* This file contains information about your project's dependencies to make subsequent restores quicker.

> Tip: If you are using the MSBuild-based .NET Core Tools a .csproj will be created instead of a project.json, but the `dotnet` commands remain the same. [Read more](https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-tools-msbuild-alpha/).
> TIP: If you are using the MSBuild-based .NET Core Tools a .csproj file will be created instead of a project.json one, but the `dotnet` commands you need to execute remain the same. For more information, see the [MSBuild-based tooling announcement](https://blogs.msdn.microsoft.com/dotnet/2016/11/16/announcing-net-core-tools-msbuild-alpha/) on the .NET blog.

![dotnet restore command](media/with-visual-studio-code/dotnetrestore.png)

![Image dotnet restore](media/with-visual-studio-code/dotnetRestore.PNG)
4. Run the "Hello World" program:

4. Run the "Hello World" program by typing `dotnet run`
* Type `dotnet run`.

![dotnetRun](media/with-visual-studio-code/dotnetRun.PNG)
![dotnet run command](media/with-visual-studio-code/dotnetrun.png)

You can also watch a short video tutorial for further setup help on [Windows](https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-using-CSharp-and-NET-Core), [macOS](https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-using-CSharp-and-NET-Core-on-MacOS), or [Linux](https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-Csharp-dotnet-Core-Ubuntu).

## Debug
1. Open Program.cs by clicking on it. The first time you open a C# file in VS Code omnisharp will load in the editor.
1. Open Program.cs by clicking on it. The first time you open a C# file in VS Code, OmniSharp will load in the editor.

![Open Program.cs file](media/with-visual-studio-code/opencs.png)

2. VS Code will prompt you to add the missing assets to build and debug your app. Click **Yes**.

![Prompt for missing assets](media/with-visual-studio-code/missing-assets.png)

![OpenCS](media/with-visual-studio-code/OpenCS.PNG)
2. Open the Debug tab on the left side. The icon is a bug with a cancel line through it.
* You can also open the Debug tab by selecting View > Debug
3. To open the Debug view, click on the Debugging icon on the left side menu.

![OpenDebug](media/with-visual-studio-code/OpenDebug.PNG)
2. Locate the green arrow at the top of the pane. Make sure the drop down next to it has `.NET Core Launch (console)` selected.
![Open the Debug tab](media/with-visual-studio-code/opendebug.png)

![SelectCore](media/with-visual-studio-code/SelectCore.PNG)
3. Add a breakpoint to your project by clicking in the space left of the line numbers in the editor.
4. Locate the green arrow at the top of the pane. Make sure the drop-down next to it has `.NET Core Launch (console)` selected.

![SetBreakpoint](media/with-visual-studio-code/SetBreakpoint.PNG)
4. Hit F5 or the green arrow to start debugging. The debugger stops execution of your program when it reaches the breakpoint you set in (3) above.
![Select .NET Core](media/with-visual-studio-code/selectcore.png)

5. Add a breakpoint to your project by clicking on the **editor margin** (the space on the left of the line numbers in the editor).

![Set a Breakpoint](media/with-visual-studio-code/setbreakpoint.png)

6. Hit <kbd>F5</kbd> or the green arrow to start debugging. The debugger stops execution of your program when it reaches the breakpoint you set the previous step.
* While debugging you can view your local variables in the top left pane or use the debug console.

![RunDebug](media/with-visual-studio-code/RunDebug.PNG)
6. Hit the green arrow at the top to continue debugging or press the red square to stop.
![Run and Debug](media/with-visual-studio-code/rundebug.png)

7. Hit the green arrow at the top to continue debugging or press the red square to stop.

## See also
- [Setting up Visual Studio Code](https://code.visualstudio.com/docs/setup/setup-overview)
- [Debugging in Visual Studio Code](https://code.visualstudio.com/Docs/editor/debugging)