|
|
|
|
#!meta
|
|
|
|
|
|
|
|
|
|
{"kernelInfo":{"defaultKernelName":"csharp","items":[{"aliases":[],"languageName":"csharp","name":"csharp"}]}}
|
|
|
|
|
|
|
|
|
|
#!markdown
|
|
|
|
|
|
|
|
|
|
# 管理相关项目
|
|
|
|
|
|
|
|
|
|
#!markdown
|
|
|
|
|
|
|
|
|
|
## 编译并启动项目
|
|
|
|
|
|
|
|
|
|
#!pwsh
|
|
|
|
|
|
|
|
|
|
# 编译整个解决方案
|
|
|
|
|
dotnet build ..\HttpClientStudy.sln
|
|
|
|
|
|
|
|
|
|
#!markdown
|
|
|
|
|
|
|
|
|
|
## 发布项目
|
|
|
|
|
|
|
|
|
|
#!pwsh
|
|
|
|
|
|
|
|
|
|
# 可以发布整个项目,但要发布到默认目录下,指定输出目录的话,会把所有项目都发布到一个目录,造成混乱。
|
|
|
|
|
# dotnet publish ..\HttpClientStudy.sln
|
|
|
|
|
|
|
|
|
|
# 分项目发布到Docs目录下
|
|
|
|
|
dotnet publish ..\HttpClientStudy.Config\HttpClientStudy.Config.csproj -c Release -o .\Publish\HttpClientStudy.Config
|
|
|
|
|
dotnet publish ..\HttpClientStudy.Model\HttpClientStudy.Model.csproj -c Release -o .\Publish\HttpClientStudy.Model
|
|
|
|
|
dotnet publish ..\HttpClientStudy.Core\HttpClientStudy.Core.csproj -c Release -o .\Publish\HttpClientStudy.Core
|
|
|
|
|
dotnet publish ..\HttpClientStudy.Service\HttpClientStudy.Service.csproj -c Release -o .\Publish\HttpClientStudy.Service
|
|
|
|
|
dotnet publish ..\HttpClientStudy.WebApp\HttpClientStudy.WebApp.csproj -c Release -o .\Publish\HttpClientStudy.WebApp
|
|
|
|
|
dotnet publish ..\HttpClientStudy.WebClient\HttpClientStudy.WebClient.csproj -c Release -o .\Publish\HttpClientStudy.WebClient
|
|
|
|
|
|
|
|
|
|
#!markdown
|
|
|
|
|
|
|
|
|
|
## 启动WebApi
|
|
|
|
|
|
|
|
|
|
#!pwsh
|
|
|
|
|
|
|
|
|
|
# 编译并启动WebApi项目
|
|
|
|
|
Start-Process -FilePath dotnet -ArgumentList "run --project ..\HttpClientStudy.WebApp\HttpClientStudy.WebApp.csproj"
|
|
|
|
|
|
|
|
|
|
#!pwsh
|
|
|
|
|
|
|
|
|
|
#启动已发布的WebApi项目
|
|
|
|
|
Start-Process -FilePath "Publish\HttpClientStudy.WebApp\HttpClientStudy.WebApp.exe"
|
|
|
|
|
|
|
|
|
|
#!markdown
|
|
|
|
|
|
|
|
|
|
## 关闭WebApi
|
|
|
|
|
|
|
|
|
|
#!pwsh
|
|
|
|
|
|
|
|
|
|
# 关闭项目进程
|
|
|
|
|
$WebAppProcName ="HttpClientStudy.WebApp";
|
|
|
|
|
$WebAppProc = Get-Process $WebAppProcName -ErrorAction Ignore
|
|
|
|
|
if($null -eq $WebAppProc)
|
|
|
|
|
{
|
|
|
|
|
Write-Host "进程没有找到,可能已经退出"
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
$WebAppProc.Kill();
|
|
|
|
|
Write-Host "$WebAppProcName 进程已退出"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#!markdown
|
|
|
|
|
|
|
|
|
|
## 查看应用各种路径
|
|
|
|
|
|
|
|
|
|
#!csharp
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
//查看各种程序路径
|
|
|
|
|
{
|
|
|
|
|
var pathDic = new Dictionary<string, (string desc, string? path)>()
|
|
|
|
|
{
|
|
|
|
|
//当前运行的exe的完整路径,包含exe文件名,只用于WinForm
|
|
|
|
|
{"Application.ExecutablePath",("程序集基完整路径(仅WinForm)", "Application.ExecutablePath 只适用于WinForm") },
|
|
|
|
|
|
|
|
|
|
//程序的启动路径:只用于WinForm
|
|
|
|
|
{"Application.StartupPath",("程序集启动路径(仅WinForm)", "Application.StartupPath 只适用于WinForm") },
|
|
|
|
|
|
|
|
|
|
//当前执行的exe或启动项目的路径,通过AppContext
|
|
|
|
|
{"AppContext.BaseDirectory",("执行或启动路径", AppContext.BaseDirectory) },
|
|
|
|
|
|
|
|
|
|
//当前执行的exe的目录,不包含exe名,使用AppDomain
|
|
|
|
|
{"AppDomain.CurrentDomain.BaseDirectory",("程序集解析程序用于探测程序集的基目录", AppDomain.CurrentDomain.BaseDirectory) },
|
|
|
|
|
|
|
|
|
|
//程序安装或启动基目录 包含应用程序的目录的名称
|
|
|
|
|
{"AppDomain.CurrentDomain.SetupInformation.ApplicationBase",("程序安装或启动基目录", AppDomain.CurrentDomain.SetupInformation.ApplicationBase) },
|
|
|
|
|
|
|
|
|
|
//当前进程的主模块路径,包含exe名
|
|
|
|
|
{"Process.GetCurrentProcess().MainModule.FileName",("当前进程的主模块路径", Process.GetCurrentProcess()?.MainModule?.FileName) },
|
|
|
|
|
|
|
|
|
|
//环境变量:用户当前工作目录的完整限定路径
|
|
|
|
|
{"Environment.CurrentDirectory",("用户当前工作目录的完整限定路径", Environment.CurrentDirectory) },
|
|
|
|
|
|
|
|
|
|
//环境变量:当前exe的完整路径,包含exe名,通过命令行参数
|
|
|
|
|
{"Environment.GetCommandLineArgs()[0]",("当前exe的完整路径", Environment.GetCommandLineArgs()[0]) },
|
|
|
|
|
|
|
|
|
|
//当前工作目录的路径(可变)
|
|
|
|
|
{"Directory.GetCurrentDirectory",("当前工作目录的路径(可变)", Directory.GetCurrentDirectory()) },
|
|
|
|
|
|
|
|
|
|
//当前Assembly的加载路径,包含dll或exe名
|
|
|
|
|
{"Assembly.GetExecutingAssembly().Location",("当前Assembly的加载路径", Assembly.GetExecutingAssembly().Location) },
|
|
|
|
|
|
|
|
|
|
//入口程序集的路径
|
|
|
|
|
{"Assembly.GetEntryAssembly().Location",("入口程序集的路径", Assembly.GetEntryAssembly()?.Location) },
|
|
|
|
|
|
|
|
|
|
//已过时:当前程序集的CodeBase路径,可能为file URI格式
|
|
|
|
|
{"Assembly.GetExecutingAssembly().CodeBase",("当前程序集的CodeBase路径", Assembly.GetExecutingAssembly()?.CodeBase) },
|
|
|
|
|
|
|
|
|
|
//已过时:入口程序集的CodeBase路径,可能为file URI格式
|
|
|
|
|
{"Assembly.GetEntryAssembly().CodeBase",("入口程序集的CodeBase路径", Assembly.GetEntryAssembly()?.CodeBase) },
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var message = string.Empty;
|
|
|
|
|
foreach (var item in pathDic)
|
|
|
|
|
{
|
|
|
|
|
message += $"{item.Key} => {item.Value.path}{Environment.NewLine}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.WriteLine(message);
|
|
|
|
|
}
|