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: docfx.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -835,7 +835,7 @@
835
835
"_csharplang/proposals/csharp-14.0/null-conditional-assignment.md": "This proposal allows the null conditional operator to be used for the destination of assignment expressions. This allows you to assign a value to a property or field only if the left side is not null.",
836
836
"_csharplang/proposals/csharp-14.0/extensions.md": "This proposal enables new kinds of extension members. These new extension members support extension properties, extension static members, including extension operators.",
837
837
"_csharplang/proposals/csharp-14.0/user-defined-compound-assignment.md": "This proposal introduces user-defined compound assignment operators. Developers can override compound assignment, increment, and decrement operators.",
838
-
"_csharplang/proposals/csharp-14.0/ignored-directives.md": "This proposal allows a source file to include ignored directives. In most cases, ignored directives are used for filebased programs, for example `#!`",
838
+
"_csharplang/proposals/csharp-14.0/ignored-directives.md": "This proposal allows a source file to include ignored directives. In most cases, ignored directives are used for file-based apps, for example `#!`",
839
839
"_csharplang/proposals/csharp-14.0/extension-operators.md": "This proposal extends the proposal for extensions to include *extension operators*, where an operator can be an extension member.",
840
840
"_csharplang/proposals/csharp-14.0/named-and-optional-parameters-in-expression-trees.md": "This proposal allows an expression tree to include named and optional parameters. This enables expression trees to be more flexible in how they are constructed.",
841
841
"_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md": "Learn about any breaking changes since the initial release of C# 10 and included in C# 11",
Copy file name to clipboardExpand all lines: docs/core/whats-new/dotnet-10/sdk.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,7 +92,7 @@ The output provides a structured, machine-readable description of the command's
92
92
93
93
## File-based apps enhancements
94
94
95
-
.NET 10 brings significant updates to the file-based apps experience, including publish support and native AOT capabilities. For an introduction to file-based programs, see [Filebased programs](../../../csharp/tour-of-csharp/overview.md#file-based-programs) and [Building and running C# programs](../../../csharp/fundamentals/program-structure/index.md#building-and-running-c-programs).
95
+
.NET 10 brings significant updates to the file-based apps experience, including publish support and native AOT capabilities. For an introduction to file-based apps, see [File-based apps](../../../csharp/tour-of-csharp/overview.md#file-based-programs) and [Building and running C# programs](../../../csharp/fundamentals/program-structure/index.md#building-and-running-c-programs).
96
96
97
97
### Enhanced file-based apps with publish support and native AOT
Copy file name to clipboardExpand all lines: docs/csharp/fundamentals/program-structure/index.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,7 @@ In that case the program starts in the opening brace of `Main` method, which is
22
22
23
23
C# is a *compiled* language. In most C# programs, you use the [`dotnet build`](../../../core/tools/dotnet-build.md) command to compile a group of source files into a binary package. Then, you use the [`dotnet run`](../../../core/tools/dotnet-run.md) command to run the program. (You can simplify this process because `dotnet run` compiles the program before running it if necessary.) These tools support a rich language of configuration options and command-line switches. The `dotnet` command line interface (CLI), which is included in the .NET SDK, provides many [tools](../../../core/tools/index.md) to generate and modify C# files.
24
24
25
-
Beginning with C# 14 and .NET 10, you can create *filebased programs*, which simplifies building and running C# programs. You use the `dotnet run` command to run a program contained in a single `*.cs` file. For example, if the following snippet is stored in a file named `hello-world.cs`, you can run it by typing `dotnet run hello-world.cs`:
25
+
Beginning with C# 14 and .NET 10, you can create *file-based apps*, which simplifies building and running C# programs. You use the `dotnet run` command to run a program contained in a single `*.cs` file. For example, if the following snippet is stored in a file named `hello-world.cs`, you can run it by typing `dotnet run hello-world.cs`:
@@ -32,7 +32,7 @@ The first line of the program contains the `#!` sequence for Unix shells. The lo
32
32
./hello-world.cs
33
33
```
34
34
35
-
The source for these programs must be a single file, but otherwise all C# syntax is valid. You can use filebased programs for small command-line utilities, prototypes, or other experiments. File based programs allow [preprocessor directives](../../language-reference/preprocessor-directives.md#file-based-programs) that configure the build system.
35
+
The source for these programs must be a single file, but otherwise all C# syntax is valid. You can use file-based apps for small command-line utilities, prototypes, or other experiments. file-based apps allow [preprocessor directives](../../language-reference/preprocessor-directives.md#file-based-programs) that configure the build system.
Beginning with C# 14, programs can be [*filebased programs*](./index.md#building-and-running-c-programs), where a single file contains the program. You run *filebased programs* with the command `dotnet run <file.cs>`, or using the `#!/usr/local/share/dotnet/dotnet run` directive as the first line (unix shells only).
27
+
Beginning with C# 14, programs can be [*file-based apps*](./index.md#building-and-running-c-programs), where a single file contains the program. You run *file-based apps* with the command `dotnet run <file.cs>`, or using the `#!/usr/local/share/dotnet/dotnet run` directive as the first line (unix shells only).
Copy file name to clipboardExpand all lines: docs/csharp/fundamentals/program-structure/top-level-statements.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,7 +85,7 @@ The compiler generates a method to serve as the program entry point for a projec
85
85
|`return`|`static int Main(string[] args)`|
86
86
| No `await` or `return`|`static void Main(string[] args)`|
87
87
88
-
Beginning with C# 14, programs can be [*filebased programs*](./index.md#building-and-running-c-programs), where a single file contains the program. You run *filebased programs* with the command `dotnet run <file.cs>`, or using the `#!/usr/local/share/dotnet/dotnet run` directive as the first line (unix shells only).
88
+
Beginning with C# 14, programs can be [*file-based apps*](./index.md#building-and-running-c-programs), where a single file contains the program. You run *file-based apps* with the command `dotnet run <file.cs>`, or using the `#!/usr/local/share/dotnet/dotnet run` directive as the first line (unix shells only).
Copy file name to clipboardExpand all lines: docs/csharp/fundamentals/tutorials/file-based-programs.md
+15-13Lines changed: 15 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
-
title: Build file-based programs
3
-
description: File-based programs are command line utilities that are built and execute without a project file. The build and run commands are implicit. New syntax supports project settings in source.
2
+
title: Build file-based apps
3
+
description: File-based apps are command line utilities that are built and execute without a project file. The build and run commands are implicit. New syntax supports project settings in source.
4
4
ms.date: 08/08/2025
5
5
ms.topic: tutorial
6
6
ai-usage: ai-assisted
@@ -10,10 +10,10 @@ ai-usage: ai-assisted
10
10
# Tutorial: Build file-based C# programs
11
11
12
12
> [!IMPORTANT]
13
-
> File-based programs are a feature of .NET 10, which is in preview.
13
+
> File-based apps are a feature of .NET 10, which is in preview.
14
14
> Some information relates to prerelease product that might be modified before release. Microsoft makes no warranties, express or implied, with respect to the information provided here.
15
15
16
-
*File-based programs* are programs contained within a single `*.cs` file that are built and run without a corresponding project (`*.csproj`) file. File-based programs are ideal for learning C# because they have less complexity: The entire program is stored in a single file. File-based programs are also useful for building command line utilities. On Unix platforms, file-based programs can be run using `#!` (shebang) directives.
16
+
*File-based apps* are programs contained within a single `*.cs` file that are built and run without a corresponding project (`*.csproj`) file. File-based apps are ideal for learning C# because they have less complexity: The entire program is stored in a single file. File-based apps are also useful for building command line utilities. On Unix platforms, file-based apps can be run using `#!` (shebang) directives.
17
17
18
18
In this tutorial, you:
19
19
@@ -24,6 +24,8 @@ In this tutorial, you:
24
24
> * Add features and NuGet packages to the program.
25
25
> * Parse and process command line arguments and standard input.
26
26
27
+
You build a file-based program that writes text as ASCII art. It's declared in a single file, uses NuGet packages that implement some of the core features.
28
+
27
29
## Prerequisites
28
30
29
31
- The .NET 10 preview SDK. Download it from the [.NET download site](https://dotnet.microsoft.com/download/dotnet/10.0).
@@ -46,7 +48,7 @@ dotnet run AsciiArt.cs
46
48
47
49
The first time you run this program, the `dotnet` host builds the executable from your source file, stores build artifacts in a temporary folder, then runs the created executable. You can verify this experience by typing `dotnet run AsciiArt.cs` again. This time, the `dotnet` host determines that the executable is current, and runs the executable without building it again. You don't see any build output.
48
50
49
-
The preceding steps demonstrate that filebased programs aren't script files. They're C# source files that are built using a generated project file in a temporary folder. One of the lines of output displayed when you built the program should look something like this (on Windows):
51
+
The preceding steps demonstrate that file-based apps aren't script files. They're C# source files that are built using a generated project file in a temporary folder. One of the lines of output displayed when you built the program should look something like this (on Windows):
That output tells you where the temporary files and build outputs are placed. Throughout this tutorial, anytime you edit the source file, the `dotnet` host updates the executable before it runs.
62
64
63
-
Filebased programs are regular C# programs. The only limitation is that they must be written in one source file. You can use top-level statements or a classic `Main` method as an entry point. You can declare any types: classes, interfaces, and structs. You can structure the algorithms in a filebased program the same as you would in any C# program. You can even declare multiple namespaces to organize your code. If you find a filebased program is growing too large for a single file, you can convert it to a project based program and split the source into multiple files. Filebased programs are a great prototyping tool. You can start experimenting with minimal overhead to prove concepts and build algorithms.
65
+
File-based apps are regular C# programs. The only limitation is that they must be written in one source file. You can use top-level statements or a classic `Main` method as an entry point. You can declare any types: classes, interfaces, and structs. You can structure the algorithms in a file-based program the same as you would in any C# program. You can even declare multiple namespaces to organize your code. If you find a file-based program is growing too large for a single file, you can convert it to a project based program and split the source into multiple files. File-based apps are a great prototyping tool. You can start experimenting with minimal overhead to prove concepts and build algorithms.
64
66
65
-
In this tutorial, you build a file-based program that writes text as ASCII art. You learn how to include packages in file-based programs, process command input, and read arguments either from the command line or standard input.
67
+
## Process command line arguments
66
68
67
69
As a first step, let's write all arguments on the command line to the output. Replace the current contents of `AsciiArt.cs` with the following code:
68
70
@@ -104,7 +106,7 @@ The preceding code reads the console input until either a blank line or a `null`
104
106
105
107
```text
106
108
This is the input file
107
-
for a filebased program.
109
+
for a file-based program.
108
110
It prints the messages
109
111
from a file or the
110
112
command line.
@@ -125,7 +127,7 @@ Now your program can accept either command line arguments or standard input.
125
127
>
126
128
> Support for `#!` directives applies on unix platforms only. There isn't a similar directive for Windows to directly execute a C# program. On Windows, you must use `dotnet run` on the command line.
127
129
128
-
On unix, you can run file-based programs directly, typing the source file name on the command line instead of `dotnet run`. You need to make two changes. First, set *execute* permissions on the source file:
130
+
On unix, you can run file-based apps directly, typing the source file name on the command line instead of `dotnet run`. You need to make two changes. First, set *execute* permissions on the source file:
129
131
130
132
```bash
131
133
chmod +x AsciiArt.cs
@@ -145,11 +147,11 @@ After making these two changes, you can run the program from the command line di
145
147
./AsciiArt.cs
146
148
```
147
149
148
-
If you prefer, you can remove the extension so you can type `./AsciiArt` instead. You can add the `#!` to your source file even if you use Windows. The Windows command line doesn't support `#!`, but the C# compiler allows that directive in filebased programs on all platforms.
150
+
If you prefer, you can remove the extension so you can type `./AsciiArt` instead. You can add the `#!` to your source file even if you use Windows. The Windows command line doesn't support `#!`, but the C# compiler allows that directive in file-based apps on all platforms.
149
151
150
152
## Add features and NuGet packages to the program
151
153
152
-
Next, add a package that supports ASCII art, [Colorful.Console](https://www.nuget.org/packages/Colorful.Console). To add a package to a filebased program, you use the `#:package` directive. Add the following directive after the `#!` directive in your AsciiArt.cs file:
154
+
Next, add a package that supports ASCII art, [Colorful.Console](https://www.nuget.org/packages/Colorful.Console). To add a package to a file-based program, you use the `#:package` directive. Add the following directive after the `#!` directive in your AsciiArt.cs file:
In this tutorial, you learned to build a file-based program, where you build the program in a single C# file. These programs don't use a project file, and can use the `#!` directive on unix systems. Learners can create these programs after trying our [online tutorials](../../tour-of-csharp/tutorials/hello-world.md) and before building larger project-based programs. Filebased programs are also a great platform for command line utilities.
241
+
In this tutorial, you learned to build a file-based program, where you build the program in a single C# file. These programs don't use a project file, and can use the `#!` directive on unix systems. Learners can create these programs after trying our [online tutorials](../../tour-of-csharp/tutorials/hello-world.md) and before building larger project-based apps. File-based apps are also a great platform for command line utilities.
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/preprocessor-directives.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,9 +47,9 @@ helpviewer_keywords:
47
47
48
48
Although the compiler doesn't have a separate preprocessor, the directives described in this section are processed as if there were one. You use them to help in conditional compilation. Unlike C and C++ directives, you can't use these directives to create macros. A preprocessor directive must be the only instruction on a line.
49
49
50
-
## Filebased programs
50
+
## File-based apps
51
51
52
-
*Filebased programs* are programs that are compiled and run using `dotnet run Program.cs` (or any `*.cs` file). The C# compiler ignores these preprocessor directives, but the build system parses them to produce the output. These directives generate warnings when encountered in a project-based compilation.
52
+
*File-based apps* are programs that are compiled and run using `dotnet run Program.cs` (or any `*.cs` file). The C# compiler ignores these preprocessor directives, but the build system parses them to produce the output. These directives generate warnings when encountered in a project-based compilation.
53
53
54
54
The C# compiler ignores any preprocessor directive that starts with `#:` or `#!`.
55
55
@@ -62,7 +62,7 @@ Console.WriteLine("Hello");
62
62
63
63
The preceding code snippet informs a Unix shell to execute the file using `/usr/local/share/dotnet/dotnet run`. (Your installation directory for the `dotnet` CLI can be different on different Unix or macOS distributions). The `#!` line must be the first line in the file, and the following tokens are the program to run. You need to enable the *execute* (`x`) permission on the C# file for that feature.
64
64
65
-
The `#:` directives that are used in filebased programs include:
65
+
The `#:` directives that are used in file-based apps include:
0 commit comments