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/get-started/csharp/run-program.md
+15-12Lines changed: 15 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,8 @@
2
2
title: "How to run a program (C#)"
3
3
description: Start programming with C# in Visual Studio and run programs from a project or code file, work with assemblies, references, NuGet packages, and .NET.
4
4
ms.custom: vs-acquisition
5
-
ms.date: 2/13/2024
5
+
ms.date: 12/10/2024
6
6
ms.subservice: general-ide
7
-
8
7
ms.topic: tutorial
9
8
ms.devlang: csharp
10
9
author: ghogen
@@ -13,9 +12,9 @@ manager: mijacobs
13
12
dev_langs:
14
13
- csharp
15
14
---
16
-
# Run a C# program in Visual Studio
15
+
# Run a C# program or app in Visual Studio
17
16
18
-
How to run a program depends on what you start from, the type of program, and whether you want to run under the debugger. In the simplest case, to build and run an open project in Visual Studio:
17
+
How to run a program or start an app depends on what you start from, the type of program or app, and whether you want to run under the debugger. In the simplest case, to build and run an open project in Visual Studio:
19
18
20
19
- Press **F5**, choose **Debug** > **Start with debugging** from the Visual Studio menu, or select the green **Start** arrow and project name on the Visual Studio toolbar.
21
20
- Or, to run without debugging, press **Ctrl**+**F5** or choose **Debug** > **Start without debugging** from the Visual Studio menu.
@@ -29,9 +28,11 @@ How to run a program depends on what you start from, the type of program, and wh
29
28
30
29
## Start from a project
31
30
32
-
You can run a C# project (*.csproj* file) if it's a runnable program. If the project contains a C# file with a `Main` method, and its output is an executable or *.exe* file, it will probably run if it builds successfully. Newer versions of C# don't require a `Main` method; instead, program executions starts with top-level statements. See [Programs without Main methods](/dotnet/csharp/fundamentals/program-structure/top-level-statements). If a project has no `Main` method and no top-level statements, then it might be a class library. If so, it's not runnable on its own, but it can be referenced by other projects.
31
+
You can run a C# project (`.csproj` file) if it's a runnable program. If the project contains a C# file with a `Main` method, and its output is an executable or `.exe` file, it will probably run if it builds successfully. If your project output is an executable file, and doesn't have a `Main` method, program executions starts with top-level statements. See [Programs without Main methods](/dotnet/csharp/fundamentals/program-structure/top-level-statements). Some project types, such as class libraries, are not runnable. Class libraries are not runnable on their own, but they can be referenced by other projects.
32
+
33
+
If you're not sure if the project you have is an executable file, select the project node in Solution Explorer, and open the project properties. Either right-click on the node to bring up the context menu, and choose **Properties**, or press **Alt**+**Enter**. In the **Application** section, look for the **Output type**. If it's **Console Application**, then it's a runnable program.
33
34
34
-
1.If your program code is already in a Visual Studio project, open the project. To do so, you can double-click or tap on the *.csproj* file in Windows File Explorer, or choose **Open a project** in Visual Studio, browse to find the *.csproj* file, and select the file.
35
+
1.Open the project. To do so, you can double-click or tap on the `.csproj` file in Windows File Explorer, or choose **Open a project** in Visual Studio, browse to find the `.csproj` file, and select the file.
35
36
36
37
1. After the project loads in Visual Studio, if your Visual Studio solution has more than one project, make sure to set the project with the `Main` method as the startup project. To set the startup project, right-click on the project name or node in **Solution Explorer** and choose **Set as Startup Project** from the context menu.
37
38
@@ -50,15 +51,17 @@ You can run a C# project (*.csproj* file) if it's a runnable program. If the pro
50
51
51
52
## Start from code
52
53
53
-
If you start from a code listing, code file, or small number of files, first make sure the code is a runnable program from a trusted source. Any app with a `Main` method is probably a runnable program, but with the current version of C#, programs without `Main` methods with top-level statements can also run. You can use the Console Application template to create a project to work with the app in Visual Studio.
54
+
If have a runnable C# code sample in mind such as [this one](https://www.sanfoundry.com/csharp-program-check-given-number-even-odd/), or a runnable C# code file or files on disk, follow these steps.
55
+
56
+
First make sure the code is a runnable program from a trusted source. Any app with a `Main` method is probably a runnable program, but with the current version of C#, programs without `Main` methods with top-level statements can also run. You can use the Console Application template to create a project in Visual Studio, and then copy the code intoit.
54
57
55
-
### Code listing for a single file
58
+
### A single code file
56
59
57
60
1. Start Visual Studio, choose **Create a new project**, and choose the C# **Console App** project.
58
-
1. Replace all the code in the project *.cs* file with the contents of your code listing or file. If the code you want to use is on the web, or in a single file, it might be easiest to select the code, copy it to the clipboard, and paste it into a code file in the Visual Studio project.
59
-
1. Rename the project *.cs* file to match your code file name.
61
+
1. Replace all the code in the project `.cs` file with the contents of your code or file. If the code you want to use is on the web, or in a single file, it might be easiest to select the code, copy it to the clipboard, and paste it into a code file in the Visual Studio project.
62
+
1. Rename the project `.cs` file to match your code file name.
60
63
61
-
### Several code listings or files on disk
64
+
### Several code files on disk
62
65
63
66
1. Start Visual Studio, and create a new project of the appropriate type. Use the C# **Console App** if you're not sure.
64
67
1. In the new project, replace all the code in the project code file with the contents of your first code listing or file.
@@ -69,7 +72,7 @@ If you start from a code listing, code file, or small number of files, first mak
69
72
70
73
### Several files in a folder
71
74
72
-
If you have a folder with many files, first check for a project or solution file. Programs that Visual Studio creates have project and solution files. In Windows File Explorer, look for files with the *.csproj* or *.sln* extension. Double-click the *.csproj* file to open it in Visual Studio. See [Start from a Visual Studio solution or project](#start-from-a-project).
75
+
If you have a folder with many files, first check for a project or solution file. Programs that Visual Studio creates have project and solution files. In Windows File Explorer, look for files with the `.csproj` or `.sln` extension. Double-click the `.csproj` file to open it in Visual Studio. See [Start from a Visual Studio solution or project](#start-from-a-project).
73
76
74
77
If the code is from another development environment, there's no project file. Open the folder by choosing **Open** > **Folder** in Visual Studio. See [Develop code without projects or solutions](../../ide/develop-code-in-visual-studio-without-projects-or-solutions.md).
Copy file name to clipboardExpand all lines: docs/ide/code-styles-and-code-cleanup.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
title: Code style options and code cleanup
3
-
description: Learn how to configure Visual Studio to apply code style preferences using the Code Cleanup (Visual Studio 2019) and Format Document (Visual Studio 2017) commands.
3
+
description: Learn how to configure Visual Studio to apply code style preferences using the Code Cleanup command.
Copy file name to clipboardExpand all lines: docs/ide/how-to-change-fonts-and-colors-in-visual-studio.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -137,7 +137,7 @@ You can change the font and text size for all the IDE frame and tool windows, or
137
137
138
138
### Preserve font settings across theme changes
139
139
140
-
With Visual Studio 2002 version 17.12, you can now preserve your font and font size preferences across theme changes. This functionality is enabled by default. When you switch themes in Visual Studio, your custom font face and size settings remain unchanged, while the font color updates with the new theme.
140
+
With Visual Studio 2022 version 17.12, you can now preserve your font and font size preferences across theme changes. This functionality is enabled by default. When you switch themes in Visual Studio, your custom font face and size settings remain unchanged, while the font color updates with the new theme.
141
141
142
142
If you prefer to have font selections change with the theme, select **Tools** > **Manage Preview Features** and uncheck **Separate font settings from color themes selection (requires restart)**.
0 commit comments