new: 添加新项目

bicijinlian-patch-1
bicijinlian 2 years ago
parent 2eb5352ace
commit 689b5bc098

@ -0,0 +1,672 @@
{
"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
}

@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,40 @@
namespace DotnetDemo.CApp
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("===================== 程序开始执行 =====================");
if (args != null && args?.Length > 0)
{
Console.WriteLine($"共有{args?.Length}个命令行参数,分别是[{string.Join(" | ", args ?? new string[]{})}]");
}
else
{
Console.WriteLine("没有命令行参数");
}
#if DEBUG
Console.WriteLine("构建模式Debug");
#else
Console.WriteLine("构建模式Realse");
#endif
Console.WriteLine($"操作系统版本:{System.Environment.OSVersion}");
Console.WriteLine($"64位操作系统{System.Environment.Is64BitOperatingSystem}");
Console.WriteLine($"主机名:{System.Environment.MachineName}");
Console.WriteLine($"系统帐户名:{System.Environment.UserName}");
Console.WriteLine($"程序域:{System.Environment.UserDomainName}");
Console.WriteLine($"用户交互模式:{System.Environment.UserInteractive}");
Console.WriteLine($"进程数:{System.Environment.ProcessorCount}");
Console.WriteLine($"进程标识:{System.Environment.ProcessId}");
Console.WriteLine($"64位进程{System.Environment.Is64BitProcess}");
Console.WriteLine($"线程托管ID{System.Environment.CurrentManagedThreadId}");
Console.WriteLine($"当前目录:{System.Environment.CurrentDirectory}");
Console.WriteLine($"程序文件:{System.Environment.ProcessPath}");
Console.WriteLine("===================== 程序运行结束 =====================");
}
}
}

@ -0,0 +1,8 @@
{
"profiles": {
"DotnetDemo.CApp": {
"commandName": "Project",
"commandLineArgs": "fromLaunchSettings.json=demo"
}
}
}

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.33516.290
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotnetDemo.CApp", "DotnetDemo.CApp\DotnetDemo.CApp.csproj", "{9E9FEF86-6331-479F-A504-CE20C5A8F3F7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9E9FEF86-6331-479F-A504-CE20C5A8F3F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9E9FEF86-6331-479F-A504-CE20C5A8F3F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9E9FEF86-6331-479F-A504-CE20C5A8F3F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9E9FEF86-6331-479F-A504-CE20C5A8F3F7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CCD11D97-2EFE-4292-9786-DDA65292F072}
EndGlobalSection
EndGlobal
Loading…
Cancel
Save