dotnet-run
Run .NET applications from source code
TLDR
Run the project in the current directory
Run a specific project
Run the project with specific arguments
Run the project using a target framework moniker
Specify architecture and OS, available since .NET 6 (Don't use --runtime with these options)
SYNOPSIS
dotnet run [options] [project | solution | directory] [-- application-arguments]
PARAMETERS
--project PATH
Specifies the path to the project file (e.g., .csproj, .fsproj), solution file (.sln), or directory containing the project to run. If omitted, dotnet run searches the current directory.
--no-build
Skips the implicit build step before running. Requires the project to be already built.
--configuration CONFIG | -c CONFIG
Sets the build configuration. Common values are Debug (default) or Release.
--framework FRAMEWORK_ID | -f FRAMEWORK_ID
Runs the application for a specific target framework defined in the project file (e.g., net8.0).
--runtime RUNTIME_IDENTIFIER | -r RUNTIME_IDENTIFIER
Specifies the target runtime to run the application (e.g., linux-x64).
--launch-profile NAME
Uses a named launch profile from launchSettings.json to set environment variables or command-line arguments.
--no-launch-profile
Prevents the launchSettings.json file from being loaded, ignoring any launch profiles.
--verbosity LEVEL | -v LEVEL
Sets the verbosity level of the command. Possible levels include q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].
--property PROPERTY | -p PROPERTY
Sets or overrides one or more MSBuild properties.
--
A separator used to pass arguments directly to the application being run. All arguments following -- are treated as application arguments, not dotnet run options.
DESCRIPTION
dotnet run is a fundamental command within the .NET Command Line Interface (CLI) that provides a convenient way to compile and execute a .NET application directly from its source code. It's primarily used during the development and testing phases of an application, offering a quick feedback loop without needing to manually build, publish, and then launch the resulting executable or DLL.
When invoked, dotnet run first implicitly performs a dotnet build operation on the specified project (or the current directory's project if none is specified). This ensures that the latest source code changes are compiled into an executable or DLL. Once the build is successful, the command then proceeds to execute the compiled output.
This command abstracts away the complexities of locating the built assembly and invoking the correct runtime, making it exceptionally user-friendly for developers. It simplifies the workflow by integrating the build and run steps into a single command, ideal for rapid prototyping, debugging, and iterative development cycles on Linux and other platforms. You can also pass arguments directly to your application using a special separator.
CAVEATS
- Development Tool: Primarily intended for development and testing. For production deployments, dotnet publish followed by direct execution is recommended.
- Implicit Build: The implicit build can sometimes mask underlying build errors if not paying close attention to the output.
- SDK Requirement: Requires the .NET SDK to be installed on the system, not just the runtime.
- Performance: Includes a build step, which can add overhead compared to directly executing an already published application.
PASSING ARGUMENTS TO THE APPLICATION
One of the most common uses of dotnet run is to pass arguments directly to the application. This is achieved using the special -- separator. All text after -- on the command line is passed as command-line arguments to the executed .NET application, rather than being interpreted as options for dotnet run itself. For example, dotnet run -- --environment Production --port 8080 would pass --environment Production and --port 8080 to your application.
INTEGRATION WITH LAUNCHSETTINGS.JSON
For ASP.NET Core and other web applications, dotnet run can optionally leverage launch profiles defined in Properties/launchSettings.json. These profiles allow you to configure environment variables, application arguments, and other settings for different execution scenarios (e.g., running with IIS Express, Kestrel, or Docker). By default, dotnet run will try to use the first suitable launch profile unless --no-launch-profile is specified or a specific profile is chosen with --launch-profile NAME.
HISTORY
The dotnet run command was introduced as a core part of the initial .NET Core CLI, which began gaining prominence around 2016 with the release of .NET Core 1.0. Its design philosophy was to provide a simplified, cross-platform development experience by integrating common build and run tasks. Over subsequent versions of .NET Core and later .NET 5+, dotnet run has remained a steadfast and heavily used command, evolving primarily through additional options and deeper integration with features like launch profiles, but its fundamental purpose as a convenient development tool has remained consistent.
SEE ALSO
dotnet build(1), dotnet publish(1), dotnet restore(1), dotnet clean(1), dotnet new(1), dotnet exec(1)