- 主要作用
- 自动编译
- 如果代码有更改,会触发隐式的 dotnet build,生成最新版本。
- 运行应用程序
- 直接启动编译后的程序(默认生成 DLL,通过宿主运行)。
- 开发效率工具
- 格式
dotnet run [options] [[--] <additional arguments>...]
- [options]:选项
- [–]:分隔CLI参数和应用参数
- [<additional arguments>…] :额外参数列表,用空格隔开(转发到正在运行的应用程序中)
参数 | 缩写 | 作用 | 示例 |
---|
–configuration <CONFIGURATION> | -c | 指定运行的配置(Debug /Release ) | dotnet run -c Debug |
–framework <FRAMEWORK> | -f | 指定运行的目标框架 | dotnet run --framework netcoreapp3.1 |
–runtime <RUNTIME_IDENTIFIER> | -r | 指定运行的目标运行时(win-x64 /linux-x64 ) | dotnet run --runtime linux-x64 |
–project <project> | | 要运行的项目文件的路径(如果只有一个项目,则默认使用当前目录) | dotnet run --project ./src/MyApp/MyApp.csproj |
–property <property> | -p | 设置 MSBuild 属性 | dotnet run -p:Version=1.2.3 / dotnet run --property:DefineConstants="DEBUG,TRACE" |
–launch-profile <launch-profile> | | 启动应用程序时使用的启动配置文件名称(如果有,Development /Production ) | dotnet run --launch-profile Development |
–no-launch-profile | | 忽略使用launchSettings.json配置应用 | dotnet run --no-launch-profile |
–no-build | | 跳过编译,直接运行已生成的程序 | dotnet run --no-build |
–interactive | | 允许命令停止和等待用户输入或操作(例如:用以完成身份验证) | dotnet run --interactive |
–no-restore | | 跳过自动还原 NuGet 包 | dotnet run --no-restore |
–self-contained | –sc | 随应用程序一起发布.NET运行时,这样就不需要在目标计算机上安装运行时。如果指定了运行时标识符,则默认值为true | dotnet run --self-contained -r linux-x64 |
–no-self-contained | | 将应用程序发布为依赖框架的应用程序,目标计算机上必须安装兼容的.NET运行时才能运行该应用程序 | dotnet run --no-self-contained -r win-x64 |
–verbosity <LEVEL> | -v | 控制日志详细程度(quiet /minimal /normal /detailed /diagnostic ) | dotnet run -v minimal |
–arch <arch> | -a | 目标体系结构(x64 /arm64 ) | dotnet run --arch x64 |
–os <os> | | 目标操作系统(linux /windows ) | dotnet run --os linux |
–help | -?,-h | 显示命令行帮助 | dotnet run -h |
# 指定Debug模式、指定运行时.NET框架、指定运行项目、指定打印运行日志、传入运行时命令行参数(用空格隔开)
dotnet run -c Debug -f netcoreapp3.1 -p /home/lxh/ConsolePingcha/ConsolePingcha.csproj --verbosity detailed -- "/home/lxh/LevelAdjust2Data_1.txt" 1 1 0 20 0.01 0.1 0 0 10
- 示例
