Skip to content

Commit af508fd

Browse files
authored
Update file-based app functionality in command reference (#48738)
* add file based changes for dotnet build * add file based command for dotnet clean * add file-based app options for dotnet-run * add file-based app details for dotnet publish * add file-based app info for dotnet-restore * Fix indentation * add in file command * make consistency edits across commands * Specify the version file-based programs are available in. * apply changes from review feedback * move project-solution-file arguments to an include file * add trailing newline to include * specify behavior of dotnet run for arguments and using file option * Add trailing newline at end of file
1 parent a59d04f commit af508fd

File tree

6 files changed

+119
-54
lines changed

6 files changed

+119
-54
lines changed

docs/core/tools/dotnet-build.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
22
title: dotnet build command
33
description: The dotnet build command builds a project and all of its dependencies.
4-
ms.date: 11/27/2023
4+
ms.date: 09/24/2025
55
---
66
# dotnet build
77

8-
**This article applies to:** ✔️ .NET Core 3.1 SDK and later versions
8+
**This article applies to:** ✔️ .NET 6 and later versions
99

1010
## Name
1111

12-
`dotnet build` - Builds a project and all of its dependencies.
12+
`dotnet build` - Builds a project, solution, or file-based app and all of its dependencies.
1313

1414
## Synopsis
1515

1616
```dotnetcli
17-
dotnet build [<PROJECT>|<SOLUTION>] [-a|--arch <ARCHITECTURE>]
17+
dotnet build [<PROJECT>|<SOLUTION>|<FILE>] [-a|--arch <ARCHITECTURE>]
1818
[--artifacts-path <ARTIFACTS_DIR>]
1919
[-c|--configuration <CONFIGURATION>] [-f|--framework <FRAMEWORK>]
2020
[--disable-build-servers]
@@ -23,7 +23,7 @@ dotnet build [<PROJECT>|<SOLUTION>] [-a|--arch <ARCHITECTURE>]
2323
[-o|--output <OUTPUT_DIRECTORY>]
2424
[-p|--property:<PROPERTYNAME>=<VALUE>]
2525
[-r|--runtime <RUNTIME_IDENTIFIER>]
26-
[--self-contained [true|false]] [--source <SOURCE>]
26+
[-sc|--self-contained [true|false]] [--source <SOURCE>]
2727
[--tl:[auto|on|off]] [--use-current-runtime, --ucr [true|false]]
2828
[-v|--verbosity <LEVEL>] [--version-suffix <VERSION_SUFFIX>]
2929
@@ -32,16 +32,14 @@ dotnet build -h|--help
3232

3333
## Description
3434

35-
The `dotnet build` command builds the project and its dependencies into a set of binaries. The binaries include the project's code in Intermediate Language (IL) files with a *.dll* extension. Depending on the project type and settings, other files may be included, such as:
35+
The `dotnet build` command builds the project, solution, or file-based app and its dependencies into a set of binaries. The binaries include the project's code in Intermediate Language (IL) files with a *.dll* extension. Depending on the project type and settings, other files may be included, such as:
3636

37-
- An executable that can be used to run the application, if the project type is an executable targeting .NET Core 3.0 or later.
37+
- An executable that can be used to run the application.
3838
- Symbol files used for debugging with a *.pdb* extension.
3939
- A *.deps.json* file, which lists the dependencies of the application or library.
4040
- A *.runtimeconfig.json* file, which specifies the shared runtime and its version for an application.
4141
- Other libraries that the project depends on (via project references or NuGet package references).
4242

43-
For executable projects targeting versions earlier than .NET Core 3.0, library dependencies from NuGet are typically NOT copied to the output folder. They're resolved from the NuGet global packages folder at run time. With that in mind, the product of `dotnet build` isn't ready to be transferred to another machine to run. To create a version of the application that can be deployed, you need to publish it (for example, with the [dotnet publish](dotnet-publish.md) command). For more information, see [.NET Application Deployment](../deploying/index.md).
44-
4543
For executable projects targeting .NET Core 3.0 and later, library dependencies are copied to the output folder. This means that if there isn't any other publish-specific logic (such as Web projects have), the build output should be deployable.
4644

4745
### Implicit restore
@@ -64,7 +62,7 @@ To produce a library, omit the `<OutputType>` property or change its value to `L
6462

6563
### MSBuild
6664

67-
`dotnet build` uses MSBuild to build the project, so it supports both parallel and incremental builds. For more information, see [Incremental Builds](/visualstudio/msbuild/incremental-builds).
65+
`dotnet build` uses MSBuild to build the project, solution, or file-based app. It supports both parallel and incremental builds. For more information, see [Incremental Builds](/visualstudio/msbuild/incremental-builds).
6866

6967
In addition to its options, the `dotnet build` command accepts MSBuild options, such as `-p` for setting properties or `-l` to define a logger. For more information about these options, see the [MSBuild Command-Line Reference](/visualstudio/msbuild/msbuild-command-line-reference). Or you can also use the [dotnet msbuild](dotnet-msbuild.md) command.
7068

@@ -77,9 +75,7 @@ Running `dotnet build` is equivalent to running `dotnet msbuild -restore`; howev
7775

7876
## Arguments
7977

80-
`PROJECT | SOLUTION`
81-
82-
The project or solution file to build. If a project or solution file isn't specified, MSBuild searches the current working directory for a file that has a file extension that ends in either *proj* or *sln* and uses that file.
78+
[!INCLUDE [arguments-project-solution-file](../../../includes/cli-arguments-project-solution-file.md)]
8379

8480
## Options
8581

@@ -176,6 +172,14 @@ The project or solution file to build. If a project or solution file isn't speci
176172
dotnet build
177173
```
178174

175+
- Build a file-based app:
176+
177+
```dotnetcli
178+
dotnet build MyProject.cs
179+
```
180+
181+
File-based app support was added in .NET SDK 10.0.100.
182+
179183
- Build a project and its dependencies using Release configuration:
180184

181185
```dotnetcli

docs/core/tools/dotnet-clean.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: dotnet clean command
33
description: The dotnet clean command cleans the current directory.
4-
ms.date: 02/14/2020
4+
ms.date: 09/24/2025
55
---
66
# dotnet clean
77

8-
**This article applies to:** ✔️ .NET Core 3.1 SDK and later versions
8+
**This article applies to:** ✔️ .NET 6 and later versions
99

1010
## Name
1111

@@ -14,7 +14,7 @@ ms.date: 02/14/2020
1414
## Synopsis
1515

1616
```dotnetcli
17-
dotnet clean [<PROJECT>|<SOLUTION>] [--artifacts-path <ARTIFACTS_DIR>]
17+
dotnet clean [<PROJECT>|<SOLUTION>|<FILE>] [--artifacts-path <ARTIFACTS_DIR>]
1818
[-c|--configuration <CONFIGURATION>]
1919
[-f|--framework <FRAMEWORK>] [--interactive]
2020
[--nologo] [-o|--output <OUTPUT_DIRECTORY>]
@@ -30,37 +30,35 @@ The `dotnet clean` command cleans the output of the previous build. It's impleme
3030

3131
## Arguments
3232

33-
`PROJECT | SOLUTION`
34-
35-
The MSBuild project or solution to clean. If a project or solution file is not specified, MSBuild searches the current working directory for a file that has a file extension that ends in *proj* or *sln*, and uses that file.
33+
[!INCLUDE [arguments-project-solution-file](../../../includes/cli-arguments-project-solution-file.md)]
3634

3735
## Options
3836

3937
[!INCLUDE [artifacts-path](../../../includes/cli-artifacts-path.md)]
4038

4139
[!INCLUDE [configuration](../../../includes/cli-configuration-clean.md)]
4240

43-
* **`-f|--framework <FRAMEWORK>`**
41+
- **`-f|--framework <FRAMEWORK>`**
4442

4543
The [framework](../../standard/frameworks.md) that was specified at build time. The framework must be defined in the [project file](../project-sdk/overview.md). If you specified the framework at build time, you must specify the framework when cleaning.
4644

4745
[!INCLUDE [help](../../../includes/cli-help.md)]
4846

4947
[!INCLUDE [interactive](../../../includes/cli-interactive-3-0.md)]
5048

51-
* **`--nologo`**
49+
- **`--nologo`**
5250

5351
Doesn't display the startup banner or the copyright message.
5452

55-
* **`-o|--output <OUTPUT_DIRECTORY>`**
53+
- **`-o|--output <OUTPUT_DIRECTORY>`**
5654

5755
The directory that contains the build artifacts to clean. Specify the `-f|--framework <FRAMEWORK>` switch with the output directory switch if you specified the framework when the project was built.
5856

5957
- .NET 7.0.200 SDK and later
6058

6159
If you specify the `--output` option when running this command on a solution, the CLI will emit a warning (an error in 7.0.200) due to the unclear semantics of the output path. The `--output` option is disallowed because all outputs of all built projects would be copied into the specified directory, which isn't compatible with multi-targeted projects, as well as projects that have different versions of direct and transitive dependencies. For more information, see [Solution-level `--output` option no longer valid for build-related commands](../compatibility/sdk/7.0/solution-level-output-no-longer-valid.md).
6260

63-
* **`-r|--runtime <RUNTIME_IDENTIFIER>`**
61+
- **`-r|--runtime <RUNTIME_IDENTIFIER>`**
6462

6563
Cleans the output folder of the specified runtime. This is used when a [self-contained deployment](../deploying/index.md#self-contained-deployment) was created.
6664

@@ -70,13 +68,21 @@ The MSBuild project or solution to clean. If a project or solution file is not s
7068

7169
## Examples
7270

73-
* Clean a default build of the project:
71+
- Clean a default build of the project:
7472

7573
```dotnetcli
7674
dotnet clean
7775
```
7876

79-
* Clean a project built using the Release configuration:
77+
- Clean a file-based program:
78+
79+
```dotnetcli
80+
dotnet clean Program.cs.
81+
```
82+
83+
File-based app support was added in .NET SDK 10.0.100.
84+
85+
- Clean a project built using the Release configuration:
8086

8187
```dotnetcli
8288
dotnet clean --configuration Release

docs/core/tools/dotnet-publish.md

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: dotnet publish command
33
description: The dotnet publish command publishes a .NET project or solution to a directory.
4-
ms.date: 01/07/2025
4+
ms.date: 09/24/2025
55
---
66
# dotnet publish
77

8-
**This article applies to:** ✔️ .NET Core 3.1 SDK and later versions
8+
**This article applies to:** ✔️ .NET 6 and later versions
99

1010
## Name
1111

@@ -14,7 +14,7 @@ ms.date: 01/07/2025
1414
## Synopsis
1515

1616
```dotnetcli
17-
dotnet publish [<PROJECT>|<SOLUTION>] [-a|--arch <ARCHITECTURE>]
17+
dotnet publish [<PROJECT>|<SOLUTION>|<FILE>] [-a|--arch <ARCHITECTURE>]
1818
[--artifacts-path <ARTIFACTS_DIR>]
1919
[-c|--configuration <CONFIGURATION>] [--disable-build-servers]
2020
[-f|--framework <FRAMEWORK>] [--force] [--interactive]
@@ -114,13 +114,7 @@ For more information, see the following resources:
114114

115115
## Arguments
116116

117-
- **`PROJECT|SOLUTION`**
118-
119-
The project or solution to publish.
120-
121-
* `PROJECT` is the path and filename of a C#, F#, or Visual Basic project file, or the path to a directory that contains a C#, F#, or Visual Basic project file. If the directory is not specified, it defaults to the current directory.
122-
123-
* `SOLUTION` is the path and filename of a solution file (*.sln* or *.slnx* extension), or the path to a directory that contains a solution file. If the directory is not specified, it defaults to the current directory.
117+
[!INCLUDE [arguments-project-solution-file](../../../includes/cli-arguments-project-solution-file.md)]
124118

125119
## Options
126120

@@ -186,12 +180,6 @@ For more information, see the following resources:
186180

187181
If you specify a relative path when publishing a solution, all output for all projects goes into the specified folder relative to the current working directory. To make publish output go to separate folders for each project, specify a relative path by using the msbuild `PublishDir` property instead of the `--output` option. For example, `dotnet publish -p:PublishDir=.\publish` sends publish output for each project to a `publish` folder under the folder that contains the project file.
188182

189-
- .NET Core 2.x SDK
190-
191-
If you specify a relative path when publishing a project, the generated output directory is relative to the project file location, not to the current working directory.
192-
193-
If you specify a relative path when publishing a solution, each project's output goes into a separate folder relative to the project file location. If you specify an absolute path when publishing a solution, all publish output for all projects goes into the specified folder.
194-
195183
[!INCLUDE [os](../../../includes/cli-os.md)]
196184

197185
- **`--sc|--self-contained [true|false]`**
@@ -268,6 +256,14 @@ For more information, see the following resources:
268256
dotnet publish --no-dependencies
269257
```
270258

259+
- Publish the file-based C# program *app.cs* in the current directory:
260+
261+
```dotnetcli
262+
dotnet publish app.cs
263+
```
264+
265+
File-based program support was added in .NET SDK 10.0.100.
266+
271267
## See also
272268

273269
- [.NET application publishing overview](../deploying/index.md)

docs/core/tools/dotnet-restore.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: dotnet restore command
33
description: Learn how to restore dependencies and project-specific tools with the dotnet restore command.
4-
ms.date: 07/19/2023
4+
ms.date: 09/24/2025
55
---
66
# dotnet restore
77

8-
**This article applies to:** ✔️ .NET Core 3.1 SDK and later versions
8+
**This article applies to:** ✔️ .NET 6 and later versions
99

1010
## Name
1111

@@ -14,7 +14,7 @@ ms.date: 07/19/2023
1414
## Synopsis
1515

1616
```dotnetcli
17-
dotnet restore [<ROOT>] [--configfile <FILE>] [--disable-build-servers]
17+
dotnet restore [<PROJECT>|<SOLUTION>|<FILE>] [--configfile <FILE>] [--disable-build-servers]
1818
[--disable-parallel]
1919
[-f|--force] [--force-evaluate] [--ignore-failed-sources]
2020
[--interactive] [--lock-file-path <LOCK_FILE_PATH>] [--locked-mode]
@@ -86,9 +86,7 @@ There are three specific settings that `dotnet restore` ignores:
8686

8787
## Arguments
8888

89-
- **`ROOT`**
90-
91-
Optional path to the project file to restore.
89+
[!INCLUDE [arguments-project-solution-file](../../../includes/cli-arguments-project-solution-file.md)]
9290

9391
## Options
9492

@@ -184,19 +182,19 @@ There are three specific settings that `dotnet restore` ignores:
184182
dotnet restore ./projects/app1/app1.csproj
185183
```
186184

187-
- Restore the dependencies and tools for the project in the current directory using the file path provided as the source:
185+
- Restore the dependencies and tools for the project in the current directory using the file path provided as the source:
188186

189187
```dotnetcli
190188
dotnet restore -s c:\packages\mypackages
191189
```
192190

193-
- Restore the dependencies and tools for the project in the current directory using the two file paths provided as sources:
191+
- Restore the dependencies and tools for the project in the current directory using the two file paths provided as sources:
194192

195193
```dotnetcli
196194
dotnet restore -s c:\packages\mypackages -s c:\packages\myotherpackages
197195
```
198196

199-
- Restore dependencies and tools for the project in the current directory showing detailed output:
197+
- Restore dependencies and tools for the project in the current directory showing detailed output:
200198

201199
```dotnetcli
202200
dotnet restore --verbosity detailed

docs/core/tools/dotnet-run.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
title: dotnet run command
33
description: The dotnet run command provides a convenient option to run your application from the source code.
4-
ms.date: 03/26/2025
4+
ms.date: 09/24/2025
55
---
66
# dotnet run
77

8-
**This article applies to:** ✔️ .NET Core 3.1 SDK and later versions
8+
**This article applies to:** ✔️ .NET 6 and later versions
99

1010
## Name
1111

@@ -14,8 +14,8 @@ ms.date: 03/26/2025
1414
## Synopsis
1515

1616
```dotnetcli
17-
dotnet run [-a|--arch <ARCHITECTURE>] [-c|--configuration <CONFIGURATION>]
18-
[-e|--environment <KEY=VALUE>]
17+
dotnet run [<applicationArguments>] [-a|--arch <ARCHITECTURE>] [-c|--configuration <CONFIGURATION>]
18+
[-e|--environment <KEY=VALUE>] [--file <FILE_PATH>]
1919
[-f|--framework <FRAMEWORK>] [--force] [--interactive]
2020
[--launch-profile <NAME>] [--no-build]
2121
[--no-dependencies] [--no-launch-profile] [--no-restore]
@@ -53,6 +53,14 @@ To run the application, the `dotnet run` command resolves the dependencies of th
5353

5454
[!INCLUDE [cli-advertising-manifests](../../../includes/cli-advertising-manifests.md)]
5555

56+
## Arguments
57+
58+
`<applicationArguments>`
59+
60+
Arguments passed to the application that is being run.
61+
62+
Any arguments that aren't recognized by `dotnet run` are passed to the application. To separate arguments for `dotnet run` from arguments for the application, use the `--` option.
63+
5664
## Options
5765

5866
- **`--`**
@@ -75,6 +83,24 @@ To run the application, the `dotnet run` command resolves the dependencies of th
7583

7684
Builds and runs the app using the specified [framework](../../standard/frameworks.md). The framework must be specified in the project file.
7785

86+
- **`--file <FILE_PATH>`**
87+
88+
The path to the file-based app to run. If a path isn't specified, the current directory is used to find and run the file. For more information on file-based apps, see [Build file-based C# apps](/dotnet/csharp/fundamentals/tutorials/file-based-programs).
89+
90+
On Unix, you can run file-based apps directly, using the source file name on the command line instead of `dotnet run`. First, ensure the file has execute permissions. Then, add a shebang line `#!` as the first line of the file, for example:
91+
92+
```csharp
93+
#!/usr/bin/env dotnet run
94+
```
95+
96+
Then you can run the file directly from the command line:
97+
98+
```bash
99+
./ConsoleApp.cs
100+
```
101+
102+
Introduced in .NET SDK 10.0.100.
103+
78104
- **`--force`**
79105

80106
Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the *project.assets.json* file.
@@ -155,6 +181,14 @@ The environment is constructed in the same order as this list, so the `-e|--envi
155181
dotnet run
156182
```
157183

184+
- Run the specified file-based app in the current directory:
185+
186+
```dotnetcli
187+
dotnet run --file ConsoleApp.cs
188+
```
189+
190+
File-based app support was added in .NET SDK 10.0.100.
191+
158192
- Run the specified project:
159193

160194
```dotnetcli
@@ -178,3 +212,16 @@ The environment is constructed in the same order as this list, so the `-e|--envi
178212
```dotnetcli
179213
dotnet run --verbosity m
180214
```
215+
216+
- Run the project in the current directory using the specified framework and pass arguments to the application:
217+
218+
```dotnetcli
219+
dotnet run -f net6.0 -- arg1 arg2
220+
```
221+
222+
In the following example, three arguments are passed to the application. One argument is passed using `-`, and two arguments are passed after `--`:
223+
224+
```dotnetcli
225+
dotnet run -f net6.0 -arg1 -- arg2 arg3
226+
```
227+

0 commit comments

Comments
 (0)