You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/tutorials/with-visual-studio-code.md
+63-17Lines changed: 63 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -104,11 +104,11 @@ In this tutorial, you created a .NET console application. In the next tutorial,
104
104
105
105
::: zone pivot="dotnet-7-0"
106
106
107
-
This tutorial shows how to create and run a .NET console application by using Visual Studio Code.
107
+
This tutorial shows how to create and run a .NET console application by using Visual Studio Code and the .NET CLI. Project tasks, such as creating, compiling, and running a project are done by using the .NET CLI. You can follow this tutorial with a different code editor and run commands in a terminal if you prefer.
108
108
109
109
## Prerequisites
110
110
111
-
*[Visual Studio Code](https://code.visualstudio.com/) with with[C# Dev Kit extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csdevkit) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery).
111
+
*[Visual Studio Code](https://code.visualstudio.com/) with the[C# extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) installed. For information about how to install extensions on Visual Studio Code, see [VS Code Extension Marketplace](https://code.visualstudio.com/docs/editor/extension-gallery).
112
112
* The [.NET 7 SDK](https://dotnet.microsoft.com/download/dotnet/7.0).
113
113
114
114
## Create the app
@@ -117,16 +117,24 @@ Create a .NET console app project named "HelloWorld".
117
117
118
118
1. Start Visual Studio Code.
119
119
120
-
1.Go to the Explorer view and select **Create .NET Project**. Alternatively, you can bring up the Command Palette using Ctrl+Shift+P (Command+Shift+P on MacOS) and then type ".NET" and find and select the .NET: New Project command.
120
+
1.Select **File** > **Open Folder** (**File** > **Open...**on macOS) from the main menu.
121
121
122
-
1.After selecting the command, you'll need to choose the project template. Choose Console app.
122
+
1.In the **Open Folder** dialog, create a *HelloWorld* folder and select it. Then click **Select Folder** (**Open** on macOS).
123
123
124
-
1. Then select the location where you would like the new project to be created.
125
-
126
-
1. Give your new project a name, "HelloWorld".
124
+
The folder name becomes the project name and the namespace name by default. You'll add code later in the tutorial that assumes the project namespace is `HelloWorld`.
127
125
128
126
1. In the **Do you trust the authors of the files in this folder?** dialog, select **Yes, I trust the authors**. You can trust the authors because this folder only has files generated by .NET and added or modified by you.
129
127
128
+
1. Open the **Terminal** in Visual Studio Code by selecting **View** > **Terminal** from the main menu.
129
+
130
+
The **Terminal** opens with the command prompt in the *HelloWorld* folder.
131
+
132
+
1. In the **Terminal**, enter the following command:
133
+
134
+
```dotnetcli
135
+
dotnet new console --framework net7.0
136
+
```
137
+
130
138
The project template creates a simple application that displays "Hello, World" in the console window by calling the <xref:System.Console.WriteLine(System.String)?displayProperty=nameWithType> method in *Program.cs*.
131
139
132
140
```csharp
@@ -148,13 +156,25 @@ Create a .NET console app project named "HelloWorld".
148
156
}
149
157
```
150
158
159
+
The first time you edit a *.cs* file, Visual Studio Code prompts you to add the missing assets to build and debug your app. Select **Yes**, and Visual Studio Code creates a *.vscode* folder with *launch.json* and *tasks.json* files.
160
+
161
+
> [!NOTE]
162
+
> If you don't get the prompt, or if you accidentally dismiss it without selecting **Yes**, do the following steps to create *launch.json* and *tasks.json*:
163
+
>
164
+
>* Select **Run** > **Add Configuration** from the menu.
165
+
>* Select **.NET 5+ and .NET Core** at the **Select environment** prompt.
166
+
151
167
The code defines a class, `Program`, with a single method, `Main`, that takes a <xref:System.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.
152
168
153
169
In the latest version of C#, a new feature named [top-level statements](../../csharp/fundamentals/program-structure/top-level-statements.md) lets you omit the `Program` class and the `Main` method. Most existing C# programs don't use top-level statements, so this tutorial doesn't use this new feature. But it's available in C# 10, and whether you use it in your programs is a matter of style preference.
154
170
155
171
## Run the app
156
172
157
-
To run your app, select Run > Run without Debugging in the upper menu, or use the keyboard shortcut (Ctrl+F5). To learn more about debugging your C# project, read the [debugging documentation](https://code.visualstudio.com/docs/csharp/debugging).
173
+
Run the following command in the **Terminal**:
174
+
175
+
```dotnetcli
176
+
dotnet run
177
+
```
158
178
159
179
The program displays "Hello, World!" and ends.
160
180
@@ -181,7 +201,11 @@ Enhance the application to prompt the user for their name and display it along w
181
201
> [!IMPORTANT]
182
202
> In Visual Studio Code, you have to explicitly save changes. Unlike Visual Studio, file changes are not automatically saved when you build and run an app.
183
203
184
-
1. Select Run>Run without debugging.
204
+
1. Run the program again:
205
+
206
+
```dotnetcli
207
+
dotnet run
208
+
```
185
209
186
210
1. Respond to the prompt by entering a name and pressing the <kbd>Enter</kbd> key.
187
211
@@ -217,17 +241,23 @@ Create a .NET console app project named "HelloWorld".
217
241
218
242
1. Start Visual Studio Code.
219
243
220
-
1.Go to the Explorer view and select **Create .NET Project**. Alternatively, you can bring up the Command Palette using Ctrl+Shift+P (Command+Shift+P on MacOS) and then type ".NET" and find and select the .NET: New Project command.
244
+
1.Select **File** > **Open Folder** (**File** > **Open...**on macOS) from the main menu.
221
245
222
-
1.After selecting the command, you'll need to choose the project template. Choose Console app.
246
+
1.In the **Open Folder** dialog, create a *HelloWorld* folder and select it. Then click **Select Folder** (**Open** on macOS).
223
247
224
-
1. Then select the location where you would like the new project to be created.
248
+
The folder name becomes the project name and the namespace name by default. You'll add code later in the tutorial that assumes the project namespace is `HelloWorld`.
225
249
226
-
1.Finally, give your new project a name, "HelloWorld".
250
+
1.In the **Do you trust the authors of the files in this folder?** dialog, select **Yes, I trust the authors**. You can trust the authors because this folder only has files generated by .NET and added or modified by you.
227
251
228
-
1.Select to**Show all template options**. Set **Do not use top-level statements** to**true**. And finally, select **Create Project**.
252
+
1.Open the**Terminal** in Visual Studio Code by selecting **View** >**Terminal** from the main menu.
229
253
230
-
1. In the **Do you trust the authors of the files in this folder?** dialog, select **Yes, I trust the authors**. You can trust the authors because this folder only has files generated by .NET and added or modified by you.
254
+
The **Terminal** opens with the command prompt in the *HelloWorld* folder.
255
+
256
+
1. In the **Terminal**, enter the following command:
257
+
258
+
```dotnetcli
259
+
dotnet new console --framework net6.0 --use-program-main
260
+
```
231
261
232
262
The project template creates a simple application that displays "Hello, World" in the console window by calling the <xref:System.Console.WriteLine(System.String)?displayProperty=nameWithType> method in *Program.cs*.
233
263
@@ -243,13 +273,25 @@ Create a .NET console app project named "HelloWorld".
243
273
}
244
274
```
245
275
276
+
The first time you edit a *.cs* file, Visual Studio Code prompts you to add the missing assets to build and debug your app. Select **Yes**, and Visual Studio Code creates a *.vscode* folder with *launch.json* and *tasks.json* files.
277
+
278
+
> [!NOTE]
279
+
> If you don't get the prompt, or if you accidentally dismiss it without selecting **Yes**, do the following steps to create *launch.json* and *tasks.json*:
280
+
>
281
+
>* Select **Run** > **Add Configuration** from the menu.
282
+
>* Select **.NET 5+ and .NET Core** at the **Select environment** prompt.
283
+
246
284
The code defines a class, `Program`, with a single method, `Main`, that takes a <xref:System.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.
247
285
248
286
In the latest version of C#, a new feature named [top-level statements](../../csharp/fundamentals/program-structure/top-level-statements.md) lets you omit the `Program` class and the `Main` method. Most existing C# programs don't use top-level statements, so this tutorial doesn't use this new feature. But it's available in C# 10, and whether you use it in your programs is a matter of style preference. In the `dotnet new` command that you used to create the project, the `--use-program-main` option prevented top-level statements from being used.
249
287
250
288
## Run the app
251
289
252
-
To run your app, select Run > Run without Debugging in the upper menu, or use the unassigned keyboard shortcut. To learn more about debugging your C# project, read the [debugging documentation](https://code.visualstudio.com/docs/csharp/debugging).
290
+
Run the following command in the **Terminal**:
291
+
292
+
```dotnetcli
293
+
dotnet run
294
+
```
253
295
254
296
The program displays "Hello, World!" and ends.
255
297
@@ -276,7 +318,11 @@ Enhance the application to prompt the user for their name and display it along w
276
318
> [!IMPORTANT]
277
319
> In Visual Studio Code, you have to explicitly save changes. Unlike Visual Studio, file changes are not automatically saved when you build and run an app.
278
320
279
-
1. Select Run>Run without debugging.
321
+
1. Run the program again:
322
+
323
+
```dotnetcli
324
+
dotnet run
325
+
```
280
326
281
327
1. Respond to the prompt by entering a name and pressing the <kbd>Enter</kbd> key.
0 commit comments