|
|
|
@ -0,0 +1,362 @@
|
|
|
|
|
{
|
|
|
|
|
"cells": [
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"id": "b96595a0",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "csharp"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"source": [
|
|
|
|
|
"管理相关项目\n",
|
|
|
|
|
"==========="
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"id": "4b3b657a",
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"source": [
|
|
|
|
|
"## 编译并启动项目"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"id": "846f306a",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "pwsh"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
|
|
|
|
"适用于 .NET MSBuild 版本 17.8.22+bfbb05667\n",
|
|
|
|
|
" Determining projects to restore...\n",
|
|
|
|
|
" 已还原 C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Model\\HttpClientStudy.Model.csproj (用时 1.72 秒)。\n",
|
|
|
|
|
" 已还原 C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Config\\HttpClientStudy.Config.csproj (用时 2.09 秒)。\n",
|
|
|
|
|
" 已还原 C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Core\\HttpClientStudy.Core.csproj (用时 2.45 秒)。\n",
|
|
|
|
|
" 已还原 C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Service\\HttpClientStudy.Service.csproj (用时 2.46 秒)。\n",
|
|
|
|
|
" 已还原 C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.csproj (用时 2.45 秒)。\n",
|
|
|
|
|
" 已还原 C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.WebClient\\HttpClientStudy.WebClient.csproj (用时 2.46 秒)。\n",
|
|
|
|
|
" 已还原 C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.UnitTest\\HttpClientStudy.UnitTest.csproj (用时 2.46 秒)。\n",
|
|
|
|
|
" HttpClientStudy.Config -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Config\\bin\\Debug\\net6.0\\HttpClientStudy.Config.dll\n",
|
|
|
|
|
" HttpClientStudy.Model -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Model\\bin\\Debug\\net8.0\\HttpClientStudy.Model.dll\n",
|
|
|
|
|
" HttpClientStudy.Core -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Core\\bin\\Debug\\net8.0\\HttpClientStudy.Core.dll\n",
|
|
|
|
|
" HttpClientStudy.Service -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Service\\bin\\Debug\\net8.0\\HttpClientStudy.Service.dll\n",
|
|
|
|
|
" HttpClientStudy.WebClient -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.WebClient\\bin\\Debug\\net8.0\\HttpClientStudy.WebClient.dll\n",
|
|
|
|
|
" HttpClientStudy.WebApp -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.WebApp\\bin\\Debug\\net8.0\\HttpClientStudy.WebApp.dll\n",
|
|
|
|
|
" HttpClientStudy.UnitTest -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.UnitTest\\bin\\Debug\\net8.0\\HttpClientStudy.UnitTest.dll\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"已成功生成。\n",
|
|
|
|
|
" 0 个警告\n",
|
|
|
|
|
" 0 个错误\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"已用时间 00:00:36.54\n"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 编译整个解决方案\n",
|
|
|
|
|
"dotnet build ..\\HttpClientStudy.sln"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"id": "1decd98c",
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"source": [
|
|
|
|
|
"## 发布项目"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"id": "6d436074",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "pwsh"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
|
|
|
|
"适用于 .NET MSBuild 版本 17.8.22+bfbb05667\n",
|
|
|
|
|
" Determining projects to restore...\n",
|
|
|
|
|
" 所有项目均是最新的,无法还原。\n",
|
|
|
|
|
" HttpClientStudy.Config -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Config\\bin\\Release\\net6.0\\HttpClientStudy.Config.dll\n",
|
|
|
|
|
" HttpClientStudy.Config -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.Config\\\n",
|
|
|
|
|
"适用于 .NET MSBuild 版本 17.8.22+bfbb05667\n",
|
|
|
|
|
" Determining projects to restore...\n",
|
|
|
|
|
" 所有项目均是最新的,无法还原。\n",
|
|
|
|
|
" HttpClientStudy.Model -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Model\\bin\\Release\\net8.0\\HttpClientStudy.Model.dll\n",
|
|
|
|
|
" HttpClientStudy.Model -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.Model\\\n",
|
|
|
|
|
"适用于 .NET MSBuild 版本 17.8.22+bfbb05667\n",
|
|
|
|
|
" Determining projects to restore...\n",
|
|
|
|
|
" 所有项目均是最新的,无法还原。\n",
|
|
|
|
|
" HttpClientStudy.Config -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Config\\bin\\Release\\net6.0\\HttpClientStudy.Config.dll\n",
|
|
|
|
|
" HttpClientStudy.Model -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Model\\bin\\Release\\net8.0\\HttpClientStudy.Model.dll\n",
|
|
|
|
|
" HttpClientStudy.Core -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Core\\bin\\Release\\net8.0\\HttpClientStudy.Core.dll\n",
|
|
|
|
|
" HttpClientStudy.Core -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.Core\\\n",
|
|
|
|
|
"适用于 .NET MSBuild 版本 17.8.22+bfbb05667\n",
|
|
|
|
|
" Determining projects to restore...\n",
|
|
|
|
|
" 所有项目均是最新的,无法还原。\n",
|
|
|
|
|
" HttpClientStudy.Model -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Model\\bin\\Release\\net8.0\\HttpClientStudy.Model.dll\n",
|
|
|
|
|
" HttpClientStudy.Config -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Config\\bin\\Release\\net6.0\\HttpClientStudy.Config.dll\n",
|
|
|
|
|
" HttpClientStudy.Core -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Core\\bin\\Release\\net8.0\\HttpClientStudy.Core.dll\n",
|
|
|
|
|
" HttpClientStudy.Service -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Service\\bin\\Release\\net8.0\\HttpClientStudy.Service.dll\n",
|
|
|
|
|
" HttpClientStudy.Service -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.Service\\\n",
|
|
|
|
|
"适用于 .NET MSBuild 版本 17.8.22+bfbb05667\n",
|
|
|
|
|
" Determining projects to restore...\n",
|
|
|
|
|
" 所有项目均是最新的,无法还原。\n",
|
|
|
|
|
" HttpClientStudy.Model -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Model\\bin\\Release\\net8.0\\HttpClientStudy.Model.dll\n",
|
|
|
|
|
" HttpClientStudy.Config -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Config\\bin\\Release\\net6.0\\HttpClientStudy.Config.dll\n",
|
|
|
|
|
" HttpClientStudy.Core -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Core\\bin\\Release\\net8.0\\HttpClientStudy.Core.dll\n",
|
|
|
|
|
" HttpClientStudy.Service -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Service\\bin\\Release\\net8.0\\HttpClientStudy.Service.dll\n",
|
|
|
|
|
" HttpClientStudy.WebApp -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.WebApp\\bin\\Release\\net8.0\\HttpClientStudy.WebApp.dll\n",
|
|
|
|
|
" HttpClientStudy.WebApp -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.WebApp\\\n",
|
|
|
|
|
"适用于 .NET MSBuild 版本 17.8.22+bfbb05667\n",
|
|
|
|
|
" Determining projects to restore...\n",
|
|
|
|
|
" 所有项目均是最新的,无法还原。\n",
|
|
|
|
|
" HttpClientStudy.Model -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Model\\bin\\Release\\net8.0\\HttpClientStudy.Model.dll\n",
|
|
|
|
|
" HttpClientStudy.Config -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Config\\bin\\Release\\net6.0\\HttpClientStudy.Config.dll\n",
|
|
|
|
|
" HttpClientStudy.Core -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Core\\bin\\Release\\net8.0\\HttpClientStudy.Core.dll\n",
|
|
|
|
|
" HttpClientStudy.Service -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.Service\\bin\\Release\\net8.0\\HttpClientStudy.Service.dll\n",
|
|
|
|
|
" HttpClientStudy.WebClient -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\HttpClientStudy.WebClient\\bin\\Release\\net8.0\\HttpClientStudy.WebClient.dll\n",
|
|
|
|
|
" HttpClientStudy.WebClient -> C:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\\Publish\\HttpClientStudy.WebClient\\\n",
|
|
|
|
|
"发布结束!\n"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 可以发布整个项目,但要发布到默认目录下,指定输出目录的话,会把所有项目都发布到一个目录,造成混乱。\n",
|
|
|
|
|
"# dotnet publish ..\\HttpClientStudy.sln\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"# 分项目发布到Docs目录下\n",
|
|
|
|
|
"dotnet publish ..\\HttpClientStudy.Config\\HttpClientStudy.Config.csproj -c Release -o .\\Publish\\HttpClientStudy.Config\n",
|
|
|
|
|
"dotnet publish ..\\HttpClientStudy.Model\\HttpClientStudy.Model.csproj -c Release -o .\\Publish\\HttpClientStudy.Model\n",
|
|
|
|
|
"dotnet publish ..\\HttpClientStudy.Core\\HttpClientStudy.Core.csproj -c Release -o .\\Publish\\HttpClientStudy.Core\n",
|
|
|
|
|
"dotnet publish ..\\HttpClientStudy.Service\\HttpClientStudy.Service.csproj -c Release -o .\\Publish\\HttpClientStudy.Service\n",
|
|
|
|
|
"dotnet publish ..\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.csproj -c Release -o .\\Publish\\HttpClientStudy.WebApp\n",
|
|
|
|
|
"dotnet publish ..\\HttpClientStudy.WebClient\\HttpClientStudy.WebClient.csproj -c Release -o .\\Publish\\HttpClientStudy.WebClient\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"Write-Host \"发布结束!\""
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"id": "2c600afa",
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"source": [
|
|
|
|
|
"## 启动WebApi"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"id": "2f2b6616",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "pwsh"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 编译并启动WebApi项目\n",
|
|
|
|
|
"Start-Process -FilePath dotnet -ArgumentList \"run --project ..\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.csproj\""
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"id": "7eaf7018",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "pwsh"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [],
|
|
|
|
|
"source": [
|
|
|
|
|
"#启动已发布的WebApi项目\n",
|
|
|
|
|
"Start-Process -FilePath \"Publish\\HttpClientStudy.WebApp\\HttpClientStudy.WebApp.exe\""
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"id": "4067f4b5",
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"source": [
|
|
|
|
|
"## 关闭WebApi"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"id": "ae775f96",
|
|
|
|
|
"metadata": {
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelName": "pwsh"
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
|
|
|
|
"\n",
|
|
|
|
|
" $WebAppProcName =\"HttpClientStudy.WebApp.exe\";\n",
|
|
|
|
|
" $WebAppProc = Get-Process $WebAppProcName -ErrorAction Ignore\n",
|
|
|
|
|
" if($null -eq $WebAppProc)\n",
|
|
|
|
|
" {\n",
|
|
|
|
|
" Write-Host \"进程没有找到,可能已经退出\"\n",
|
|
|
|
|
" }\n",
|
|
|
|
|
" else {\n",
|
|
|
|
|
" $WebAppProc.Kill();\n",
|
|
|
|
|
" Write-Host \"$WebAppProcName 进程已退出\"\n",
|
|
|
|
|
" }\n",
|
|
|
|
|
"\n"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"# 关闭项目进程\n",
|
|
|
|
|
"{\n",
|
|
|
|
|
" $WebAppProcName =\"HttpClientStudy.WebApp\";\n",
|
|
|
|
|
" $WebAppProc = Get-Process $WebAppProcName -ErrorAction Ignore\n",
|
|
|
|
|
" if($null -eq $WebAppProc)\n",
|
|
|
|
|
" {\n",
|
|
|
|
|
" Write-Host \"进程没有找到,可能已经退出\"\n",
|
|
|
|
|
" }\n",
|
|
|
|
|
" else {\n",
|
|
|
|
|
" $WebAppProc.Kill();\n",
|
|
|
|
|
" Write-Host \"$WebAppProcName 进程已退出\"\n",
|
|
|
|
|
" }\n",
|
|
|
|
|
"}"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "markdown",
|
|
|
|
|
"id": "a4ef55bc",
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"source": [
|
|
|
|
|
"## 查看应用各种路径"
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
"cell_type": "code",
|
|
|
|
|
"execution_count": null,
|
|
|
|
|
"id": "7e6f752c",
|
|
|
|
|
"metadata": {},
|
|
|
|
|
"outputs": [
|
|
|
|
|
{
|
|
|
|
|
"name": "stdout",
|
|
|
|
|
"output_type": "stream",
|
|
|
|
|
"text": [
|
|
|
|
|
"Application.ExecutablePath => Application.ExecutablePath 只适用于WinForm\r\n",
|
|
|
|
|
"Application.StartupPath => Application.StartupPath 只适用于WinForm\r\n",
|
|
|
|
|
"AppContext.BaseDirectory => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\\r\n",
|
|
|
|
|
"AppDomain.CurrentDomain.BaseDirectory => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\\r\n",
|
|
|
|
|
"AppDomain.CurrentDomain.SetupInformation.ApplicationBase => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\\r\n",
|
|
|
|
|
"Process.GetCurrentProcess().MainModule.FileName => C:\\Program Files\\dotnet\\dotnet.exe\r\n",
|
|
|
|
|
"Environment.CurrentDirectory => c:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\r\n",
|
|
|
|
|
"Environment.GetCommandLineArgs()[0] => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\Microsoft.DotNet.Interactive.App.dll\r\n",
|
|
|
|
|
"Directory.GetCurrentDirectory => c:\\Users\\ruyu\\Desktop\\HttpClientStudy\\Docs\r\n",
|
|
|
|
|
"Assembly.GetExecutingAssembly().Location => \r\n",
|
|
|
|
|
"Assembly.GetEntryAssembly().Location => C:\\Users\\ruyu\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.617701\\tools\\net9.0\\any\\Microsoft.DotNet.Interactive.App.dll\r\n",
|
|
|
|
|
"Assembly.GetExecutingAssembly().CodeBase => file:///C:/Program Files/dotnet/shared/Microsoft.NETCore.App/9.0.4/System.Private.CoreLib.dll\r\n",
|
|
|
|
|
"Assembly.GetEntryAssembly().CodeBase => file:///C:/Users/ruyu/.nuget/packages/microsoft.dotnet-interactive/1.0.617701/tools/net9.0/any/Microsoft.DotNet.Interactive.App.dll\r\n",
|
|
|
|
|
"\r\n"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"source": [
|
|
|
|
|
"using System;\n",
|
|
|
|
|
"using System.IO;\n",
|
|
|
|
|
"using System.Threading;\n",
|
|
|
|
|
"using System.Threading.Tasks;\n",
|
|
|
|
|
"using System.Diagnostics;\n",
|
|
|
|
|
"using System.Reflection;\n",
|
|
|
|
|
"\n",
|
|
|
|
|
"//查看各种程序路径\n",
|
|
|
|
|
"{\n",
|
|
|
|
|
" var pathDic = new Dictionary<string, (string desc, string? path)>() \n",
|
|
|
|
|
" {\n",
|
|
|
|
|
" //当前运行的exe的完整路径,包含exe文件名,只用于WinForm\n",
|
|
|
|
|
" {\"Application.ExecutablePath\",(\"程序集基完整路径(仅WinForm)\", \"Application.ExecutablePath 只适用于WinForm\") },\n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //程序的启动路径:只用于WinForm\n",
|
|
|
|
|
" {\"Application.StartupPath\",(\"程序集启动路径(仅WinForm)\", \"Application.StartupPath 只适用于WinForm\") },\n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //当前执行的exe或启动项目的路径,通过AppContext\n",
|
|
|
|
|
" {\"AppContext.BaseDirectory\",(\"执行或启动路径\", AppContext.BaseDirectory) }, \n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //当前执行的exe的目录,不包含exe名,使用AppDomain\n",
|
|
|
|
|
" {\"AppDomain.CurrentDomain.BaseDirectory\",(\"程序集解析程序用于探测程序集的基目录\", AppDomain.CurrentDomain.BaseDirectory) }, \n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //程序安装或启动基目录 包含应用程序的目录的名称\n",
|
|
|
|
|
" {\"AppDomain.CurrentDomain.SetupInformation.ApplicationBase\",(\"程序安装或启动基目录\", AppDomain.CurrentDomain.SetupInformation.ApplicationBase) }, \n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //当前进程的主模块路径,包含exe名\n",
|
|
|
|
|
" {\"Process.GetCurrentProcess().MainModule.FileName\",(\"当前进程的主模块路径\", Process.GetCurrentProcess()?.MainModule?.FileName) }, \n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //环境变量:用户当前工作目录的完整限定路径\n",
|
|
|
|
|
" {\"Environment.CurrentDirectory\",(\"用户当前工作目录的完整限定路径\", Environment.CurrentDirectory) }, \n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //环境变量:当前exe的完整路径,包含exe名,通过命令行参数\n",
|
|
|
|
|
" {\"Environment.GetCommandLineArgs()[0]\",(\"当前exe的完整路径\", Environment.GetCommandLineArgs()[0]) }, \n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //当前工作目录的路径(可变)\n",
|
|
|
|
|
" {\"Directory.GetCurrentDirectory\",(\"当前工作目录的路径(可变)\", Directory.GetCurrentDirectory()) },\n",
|
|
|
|
|
" \n",
|
|
|
|
|
" //当前Assembly的加载路径,包含dll或exe名\n",
|
|
|
|
|
" {\"Assembly.GetExecutingAssembly().Location\",(\"当前Assembly的加载路径\", Assembly.GetExecutingAssembly().Location) },\n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //入口程序集的路径\n",
|
|
|
|
|
" {\"Assembly.GetEntryAssembly().Location\",(\"入口程序集的路径\", Assembly.GetEntryAssembly()?.Location) },\n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //已过时:当前程序集的CodeBase路径,可能为file URI格式\n",
|
|
|
|
|
" {\"Assembly.GetExecutingAssembly().CodeBase\",(\"当前程序集的CodeBase路径\", Assembly.GetExecutingAssembly()?.CodeBase) },\n",
|
|
|
|
|
"\n",
|
|
|
|
|
" //已过时:入口程序集的CodeBase路径,可能为file URI格式\n",
|
|
|
|
|
" {\"Assembly.GetEntryAssembly().CodeBase\",(\"入口程序集的CodeBase路径\", Assembly.GetEntryAssembly()?.CodeBase) },\n",
|
|
|
|
|
" };\n",
|
|
|
|
|
"\n",
|
|
|
|
|
" var message = string.Empty;\n",
|
|
|
|
|
" foreach (var item in pathDic)\n",
|
|
|
|
|
" {\n",
|
|
|
|
|
" message += $\"{item.Key} => {item.Value.path}{Environment.NewLine}\";\n",
|
|
|
|
|
" }\n",
|
|
|
|
|
"\n",
|
|
|
|
|
" Console.WriteLine(message);\n",
|
|
|
|
|
"}"
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
"metadata": {
|
|
|
|
|
"kernelspec": {
|
|
|
|
|
"display_name": ".NET (C#)",
|
|
|
|
|
"language": "C#",
|
|
|
|
|
"name": ".net-csharp"
|
|
|
|
|
},
|
|
|
|
|
"polyglot_notebook": {
|
|
|
|
|
"kernelInfo": {
|
|
|
|
|
"defaultKernelName": "csharp",
|
|
|
|
|
"items": [
|
|
|
|
|
{
|
|
|
|
|
"aliases": [],
|
|
|
|
|
"languageName": "csharp",
|
|
|
|
|
"name": "csharp"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"nbformat": 4,
|
|
|
|
|
"nbformat_minor": 5
|
|
|
|
|
}
|