Skip to content

Commit fc0c030

Browse files
authored
add -e|--environment option to dotnet run (#45539)
1 parent 60a6164 commit fc0c030

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

docs/core/tools/dotnet-run.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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: 11/27/2023
4+
ms.date: 03/26/2025
55
---
66
# dotnet run
77

@@ -15,6 +15,7 @@ ms.date: 11/27/2023
1515

1616
```dotnetcli
1717
dotnet run [-a|--arch <ARCHITECTURE>] [-c|--configuration <CONFIGURATION>]
18+
[-e|--environment <KEY=VALUE>]
1819
[-f|--framework <FRAMEWORK>] [--force] [--interactive]
1920
[--launch-profile <NAME>] [--no-build]
2021
[--no-dependencies] [--no-launch-profile] [--no-restore]
@@ -42,7 +43,7 @@ The `dotnet run` command is used in the context of projects, not built assemblie
4243
dotnet myapp.dll
4344
```
4445

45-
For more information on the `dotnet` driver, see the [.NET Command Line Tools (CLI)](index.md) topic.
46+
For more information on the `dotnet` driver, see [.NET CLI overview](index.md).
4647

4748
To run the application, the `dotnet run` command resolves the dependencies of the application that are outside of the shared runtime from the NuGet cache. Because it uses cached dependencies, it's not recommended to use `dotnet run` to run applications in production. Instead, [create a deployment](../deploying/index.md) using the [`dotnet publish`](dotnet-publish.md) command and deploy the published output.
4849

@@ -62,6 +63,14 @@ To run the application, the `dotnet run` command resolves the dependencies of th
6263

6364
[!INCLUDE [configuration](../../../includes/cli-configuration.md)]
6465

66+
- **`-e|--environment <KEY=VALUE>`**
67+
68+
Sets the specified environment variable in the process that will be run by the command. The specified environment variable is *not* applied to the `dotnet run` process.
69+
70+
Environment variables passed through this option take precedence over ambient environment variables, System.CommandLine `env` directives, and `environmentVariables` from the chosen launch profile. For more information, see [Environment variables](#environment-variables).
71+
72+
(This option was added in .NET SDK 9.0.200.)
73+
6574
- **`-f|--framework <FRAMEWORK>`**
6675

6776
Builds and runs the app using the specified [framework](../../standard/frameworks.md). The framework must be specified in the project file.
@@ -127,6 +136,17 @@ To run the application, the `dotnet run` command resolves the dependencies of th
127136

128137
[!INCLUDE [verbosity](../../../includes/cli-verbosity-minimal.md)]
129138

139+
## Environment variables
140+
141+
There are four mechanisms by which environment variables can be applied to the launched application:
142+
143+
1. Ambient environment variables from the operating system when the command is run.
144+
1. System.CommandLine `env` directives, like `[env:key=value]`. These apply to the entire `dotnet run` process, not just the project being run by `dotnet run`.
145+
1. `environmentVariables` from the chosen launch profile (`-lp`) in the project's [launchSettings.json file](/aspnet/core/fundamentals/environments#lsj), if any. These apply to the project being run by `dotnet run`.
146+
1. `-e|--environment` CLI option values (added in .NET SDK version 9.0.200). These apply to the project being run by `dotnet run`.
147+
148+
The environment is constructed in the same order as this list, so the `-e|--environment` option has the highest precedence.
149+
130150
## Examples
131151

132152
- Run the project in the current directory:

0 commit comments

Comments
 (0)