{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "dotnet run 命令使用\n", "==================" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## 使用经典 Powershell (Powershell 5及以下) " ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "# 查看 powershell 版本信息\n", "$PSVersionTable.PSVersion" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## 使用新版跨平台 Powershell (Powershell 6及以上)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!pwsh\n", "\n", "# 查看 Powershell 版本\n", "$PSVersionTable.PSVersion" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "## 使用 dotnet run 命令运行 项目或程序\n", "格式:\n", " dotnet run [applicationArguments] [options]" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 显示帮助信息" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!pwsh\n", "dotnet run --help" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 运行当前目录下的项目" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!pwsh\n", "\n", "# 先进入项目目录\n", "cd ..\\DotnetDemo.CApp\n", "\n", "dotnet run" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 指定项目文件\n", "使用 --project path/xxx.csproj 参数\n", "dotnet run --project csproj文件相对或绝对路" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!pwsh\n", "\n", "dotnet run --project ..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 编译方式参数 -c --configurartion Debug|Realese" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "# Debug 模式\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" -c Debug" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "# Reasele 模式\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" -c Release" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 目标运行时版本参数 -f freamework" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "+ .NET 5 及更高版本 netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1 net5.0 net6.0 net7.0\n", "+ .NET Standard netstandard1.0 netstandard1.1 netstandard1.2 netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1\n", "+ .NET Framework net11\n", "net20 net35 net40\n", "net403 net45 net451 net452 net46 net461 net462 net47 net471 net472 net48" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "# Reasele 模式\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" -c Debug -f net7.0" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 要传递给 MSBuild 的参数 --property \n", "要传递给MSBuild的属性参数,开如\n", "+ --property:NAME1=VALUE1;NAME2=VALUE2 [此种实际执行好像出错误,待解决]\n", "+ --property:NAME1=VALUE1 --property:NAME2=VALUE2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" -c Debug -f net7.0 --proprty verbosity=detailed --proprty restore=true" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 设置启动项参数 -lp --launch-profile \n", "指定按:项目/Properties/launchSettings.json 文件中的启动项名称指定的项启动,即是设置launchSettings.json启动项(名称)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --launch-profile DotnetDemo.CApp\n", "\n", "# 输出中有来自 launchSettings.json 的应用程序参数信息" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 禁用启动项参数 --no-launch-profile\n", "不要尝试使用launchSettings.json来配置应用程序\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --no-launch-profile\n", "\n", "# 输出中,没有来自 launchSettings.json 的应用程序参数信息" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 运行前禁用 build 参数 --no-build" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --no-build\n", "\n", "# 不编译,直接执行。如果之前没有编译过,会出错。" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 禁止运行前的项目还原 参数 --no-restore" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --no-restore\n", "\n", "# 不进行项目Neget包还原,直接执行。如果之前没有restore操作,会出错。" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 用户交互参数 --interactive\n", "是否启用用户交互模式,启用时,在程序运行中可以要求和接收用户输入数据" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --interactive true\n", "\n", "# 启用用户交互模式" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --interactive false\n", "\n", "# 禁用用户交互模式" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 发布为自包含参数 --self-contained" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --self-contained\n", "\n", "# 发布为自包含文件" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 发布为非自包含参娄 --no-self-contained" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --no-self-contained\n", "\n", "# 发布为非自包含文件" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### cpu架构参数 -a --arch" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --arch x64\n", "\n", "# 发布为x64程序" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --arch x86\n", "\n", "# 发布为x86程序" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "csharp" }, "polyglot_notebook": { "kernelName": "csharp" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "# dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --arch arm64\n", "\n", "# 发布为arm64程序,现有操作系统不支持" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "### 日志详细程序参数 -v --verbosity\n", "值为 q[uiet] m[inimal] n[ormal] d[etailed] dia[gnostic]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --verbosity quiet\n", "\n", "# q[uiet]日志等级" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --verbosity minimal\n", "\n", "# m[inimal]日志等级" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --verbosity normal\n", "\n", "# n[ormal]日志等级,结果单元中会有很多详细日志" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "dotnet_interactive": { "language": "pwsh" }, "polyglot_notebook": { "kernelName": "pwsh" } }, "outputs": [], "source": [ "#!powershell\n", "\n", "dotnet run --project \"..\\DotnetDemo.CApp\\DotnetDemo.CApp.csproj\" --verbosity detailed\n", "\n", "# d[etailed]日志等级" ] } ], "metadata": { "kernelspec": { "display_name": ".NET (C#)", "language": "C#", "name": ".net-csharp" }, "language_info": { "name": "polyglot-notebook" }, "orig_nbformat": 4, "polyglot_notebook": { "kernelInfo": { "defaultKernelName": "csharp", "items": [ { "aliases": [], "name": "csharp" } ] } } }, "nbformat": 4, "nbformat_minor": 2 }