feat:更新

main
bicijinlian 8 months ago
parent d453c312f2
commit 8fa3211b63

@ -71,8 +71,9 @@ namespace HttpClientStudy.Core.Utilities
/// 新窗口启动WebApp项目 /// 新窗口启动WebApp项目
/// </summary> /// </summary>
/// <param name="startFile">包含全路径的WebApp项目</param> /// <param name="startFile">包含全路径的WebApp项目</param>
/// <param name="args">命令参数</param>
/// <returns></returns> /// <returns></returns>
public static string RunWebApp(string startFile) public static string RunWebApp(string startFile, params string[] args)
{ {
string output = ""; string output = "";
@ -81,8 +82,8 @@ namespace HttpClientStudy.Core.Utilities
ProcessStartInfo startInfo = new ProcessStartInfo() ProcessStartInfo startInfo = new ProcessStartInfo()
{ {
FileName = "powershell.exe", FileName = "powershell.exe",
Arguments = $"Start-Process -FilePath '{startFile}'", Arguments = $"Start-Process -FilePath '{startFile}' -ArgumentList '{string.Join(" ", args)}' ",
UseShellExecute = false, UseShellExecute = true,
CreateNoWindow = false, CreateNoWindow = false,
}; };
@ -94,7 +95,7 @@ namespace HttpClientStudy.Core.Utilities
process.Start(); process.Start();
output = "新窗口启动WebApp项目已有实例在运行则窗口会自动关闭"; output = "已在新窗口中启动WebApp项目。如果已有实例在运行或者执行异常则窗口会自动关闭否则新窗口一直存在,直到手动关闭!";
} }
catch (Exception ex) catch (Exception ex)

@ -43,9 +43,9 @@ namespace HttpClientStudy.UnitTest.UtilitiesTest
[Fact] [Fact]
public void StartApp_Test() public void StartApp_Test()
{ {
var webapiDll = Path.GetFullPath("../../../../Docs/Publish/HttpClientStudy.WebApp/HttpClientStudy.WebApp.exe"); var webapiDll = Path.GetFullPath("../../../../Docs/Publish/HttpClientStudy.WebApp/HttpClientStudy.WebApp.exe", Environment.CurrentDirectory);
var result = DotnetCommondUtility.RunWebApp(webapiDll); var result = DotnetCommondUtility.RunWebApp(webapiDll,"--urls=http://localhost:8899");
_output.WriteLine(result); _output.WriteLine(result);
} }

@ -41,9 +41,17 @@ namespace HttpClientStudy.WebApp
var configBasePath = AppContext.BaseDirectory; var configBasePath = AppContext.BaseDirectory;
Console.WriteLine($"WebApp配置文件根目录{configBasePath}"); Console.WriteLine($"WebApp配置文件根目录{configBasePath}");
builder.Configuration.SetBasePath(configBasePath); builder.Configuration.SetBasePath(configBasePath);
//环境变量
builder.Configuration.AddEnvironmentVariables();
//配置文件
builder.Configuration.AddJsonFile("appsettings.json", false, true); builder.Configuration.AddJsonFile("appsettings.json", false, true);
builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", true, true); builder.Configuration.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", true, true);
builder.Configuration.AddJsonFile($"configFiles/Config.json", false, true); builder.Configuration.AddJsonFile($"configFiles/Config.json", false, true);
//命令行参数
builder.Configuration.AddCommandLine(args);
#endregion #endregion
#region 向容器注册服务 #region 向容器注册服务
@ -190,7 +198,6 @@ namespace HttpClientStudy.WebApp
builder.Services.AddHealthChecks(); builder.Services.AddHealthChecks();
//普通类 //普通类
builder.Services.AddScoped(provider => new Account() { Id = 0, Name = "服务注入示例", Password = "123456", Role = "IoC" }); builder.Services.AddScoped(provider => new Account() { Id = 0, Name = "服务注入示例", Password = "123456", Role = "IoC" });
builder.Services.AddScoped<AccountService>(); builder.Services.AddScoped<AccountService>();
#endregion #endregion

Loading…
Cancel
Save