You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HttpClientStudy/Docs/2.1.内核中的各种路径.ipynb

117 lines
4.8 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
}
},
"source": [
"# 多语言笔记:内核中的各种路径"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"搞清楚,内核执行时的各种默认目录、路径,方便解决一些引用、文件等跟路径有关的问题。"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"dotnet_interactive": {
"language": "csharp"
},
"polyglot_notebook": {
"kernelName": "csharp"
},
"vscode": {
"languageId": "polyglot-notebook"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"应用程序的基准目录 [AppContext.BaseDirectory] C:\\Users\\asus\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.522904\\tools\\net8.0\\any\\\n",
"程序安装当前基目录 [AppDomain.CurrentDomain.BaseDirectory] C:\\Users\\asus\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.522904\\tools\\net8.0\\any\\\n",
"程序安装或启动基目录 [AppDomain.CurrentDomain.SetupInformation.ApplicationBase] C:\\Users\\asus\\.nuget\\packages\\microsoft.dotnet-interactive\\1.0.522904\\tools\\net8.0\\any\\\n",
"进程主模块的完整路径 [Process.GetCurrentProcess().MainModule.FileName] C:\\Program Files\\dotnet\\dotnet.exe\n",
"当前工作目录 [Environment.CurrentDirectory] e:\\王高峰\\我的项目\\学习项目\\HttpClientStudy\\Docs\n",
"文件当前目录 [Directory.GetCurrentDirectory()] e:\\王高峰\\我的项目\\学习项目\\HttpClientStudy\\Docs\n",
"可执行程序集目录 [Assembly.GetExecutingAssembly().Location] \n",
"指定程序集目录 [Type.Assembly.Location] C:\\Program Files\\dotnet\\shared\\Microsoft.NETCore.App\\8.0.5\\System.Private.CoreLib.dll\n"
]
}
],
"source": [
"// C#中,内核执行时,各种默认路径如下:\n",
"\n",
"using System;\n",
"using System.IO;\n",
"using System.Threading;\n",
"using System.Threading.Tasks;\n",
"using System.Diagnostics;\n",
"using System.Reflection;\n",
"using Microsoft.Extensions.DependencyInjection;\n",
"\n",
"//应用程序信息\n",
"\n",
"//程序的上下文基准目录:通常是应用程序启动时的目录,也可以理解为包含可执行文件的目录\n",
"Console.WriteLine($\"应用程序的基准目录 [AppContext.BaseDirectory] {AppContext.BaseDirectory}\");\n",
"\n",
"//程序安装当前基目录 \n",
"Console.WriteLine($\"程序安装当前基目录 [AppDomain.CurrentDomain.BaseDirectory] {AppDomain.CurrentDomain.BaseDirectory}\");\n",
"\n",
"//程序安装或启动基目录\n",
"Console.WriteLine($\"程序安装或启动基目录 [AppDomain.CurrentDomain.SetupInformation.ApplicationBase] {AppDomain.CurrentDomain.SetupInformation.ApplicationBase}\");\n",
"\n",
"//进程主模块的完整路径\n",
"Console.WriteLine($\"进程主模块的完整路径 [Process.GetCurrentProcess().MainModule.FileName] {Process.GetCurrentProcess()?.MainModule?.FileName}\");\n",
"\n",
"//环境变量:当前工作目录\n",
"Console.WriteLine($\"当前工作目录 [Environment.CurrentDirectory] {Environment.CurrentDirectory}\");\n",
"\n",
"//文件当前目录:当前工作目录:不一定是启动目录\n",
"Console.WriteLine($\"文件当前目录 [Directory.GetCurrentDirectory()] {Directory.GetCurrentDirectory()}\");\n",
"\n",
"//可执行程序集目录\n",
"Console.WriteLine($\"可执行程序集目录 [Assembly.GetExecutingAssembly().Location] {Assembly.GetExecutingAssembly().Location}\");\n",
"\n",
"//指定程序集目录:可以是引用类库、指定类所在类库目录 \n",
"Console.WriteLine($\"指定程序集目录 [Type.Assembly.Location] {typeof(System.Environment).Assembly.Location}\");\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".NET (C#)",
"language": "C#",
"name": ".net-csharp"
},
"language_info": {
"name": "python"
},
"polyglot_notebook": {
"kernelInfo": {
"defaultKernelName": "csharp",
"items": [
{
"aliases": [],
"name": "csharp"
}
]
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}