dotnet run command - .NET CLI (original) (raw)

This article applies to: ✔️ .NET Core 3.1 SDK and later versions

Name

dotnet run - Runs source code without any explicit compile or launch commands.

Synopsis

dotnet run [-a|--arch <ARCHITECTURE>] [-c|--configuration <CONFIGURATION>]
    [-e|--environment <KEY=VALUE>]
    [-f|--framework <FRAMEWORK>] [--force] [--interactive]
    [--launch-profile <NAME>] [--no-build]
    [--no-dependencies] [--no-launch-profile] [--no-restore]
    [--os <OS>] [--project <PATH>] [-r|--runtime <RUNTIME_IDENTIFIER>]
    [--tl:[auto|on|off]] [-v|--verbosity <LEVEL>]
    [[--] [application arguments]]

dotnet run -h|--help

Description

The dotnet run command provides a convenient option to run your application from the source code with one command. It's useful for fast iterative development from the command line. The command depends on the dotnet build command to build the code. Any requirements for the build apply to dotnet run as well.

Note

dotnet run doesn't respect arguments like /property:property=value, which are respected by dotnet build.

Output files are written into the default location, which is bin/<configuration>/<target>. For example if you have a netcoreapp2.1 application and you run dotnet run, the output is placed in bin/Debug/netcoreapp2.1. Files are overwritten as needed. Temporary files are placed in the obj directory.

If the project specifies multiple frameworks, executing dotnet run results in an error unless the -f|--framework <FRAMEWORK> option is used to specify the framework.

The dotnet run command is used in the context of projects, not built assemblies. If you're trying to run a framework-dependent application DLL instead, you must use without a command. For example, to run myapp.dll, use:

dotnet myapp.dll

For more information on the dotnet driver, see .NET CLI overview.

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 using the dotnet publish command and deploy the published output.

Implicit restore

You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To disable implicit restore, use the --no-restore option.

The dotnet restore command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.

For information about how to manage NuGet feeds, see the dotnet restore documentation.

This command supports the dotnet restore options when passed in the long form (for example, --source). Short form options, such as -s, are not supported.

Workload manifest downloads

When you run this command, it initiates an asynchronous background download of advertising manifests for workloads. If the download is still running when this command finishes, the download is stopped. For more information, see Advertising manifests.

Options

--property:<NAME1>=<VALUE1>;<NAME2>=<VALUE2>  
--property:<NAME1>=<VALUE1> --property:<NAME2>=<VALUE2>  

The short form -p can be used for --property. If the argument provided for the option contains =, -p is accepted as short for --property. Otherwise, the command assumes that -p is short for --project.
To pass --property to the application rather than set an MSBuild property, provide the option after the -- syntax separator, for example:

dotnet run -- --property name=value  

Environment variables

There are four mechanisms by which environment variables can be applied to the launched application:

  1. Ambient environment variables from the operating system when the command is run.
  2. 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.
  3. environmentVariables from the chosen launch profile (-lp) in the project's launchSettings.json file, if any. These apply to the project being run by dotnet run.
  4. -e|--environment CLI option values (added in .NET SDK version 9.0.200). These apply to the project being run by dotnet run.

The environment is constructed in the same order as this list, so the -e|--environment option has the highest precedence.

Examples

dotnet run  
dotnet run --project ./projects/proj1/proj1.csproj  
dotnet run --property:Configuration=Release  
dotnet run --configuration Release -- --help  
dotnet run --verbosity m