From 0691b654e114274b73e5a0aa1c1b0842445e57ef Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 23 Jan 2021 01:16:24 +0800 Subject: feat: Now configuration uses environment variables starts with 'Timeline_'. And remove work dir config in launch profiles. --- BackEnd/.vscode/launch.json | 36 +++++++++++++++++ BackEnd/.vscode/tasks.json | 42 ++++++++++++++++++++ BackEnd/Timeline/Program.cs | 51 ++++++++++++++----------- BackEnd/Timeline/Properties/launchSettings.json | 9 ++--- 4 files changed, 109 insertions(+), 29 deletions(-) create mode 100644 BackEnd/.vscode/launch.json create mode 100644 BackEnd/.vscode/tasks.json diff --git a/BackEnd/.vscode/launch.json b/BackEnd/.vscode/launch.json new file mode 100644 index 00000000..9eef271c --- /dev/null +++ b/BackEnd/.vscode/launch.json @@ -0,0 +1,36 @@ +{ + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "version": "0.2.0", + "configurations": [ + { + "name": ".NET Core Launch (web)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/Timeline/bin/Debug/net5.0/Timeline.dll", + "args": [], + "cwd": "${workspaceFolder}/Timeline", + "stopAtEntry": false, + // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser + "serverReadyAction": { + "action": "openExternally", + "pattern": "\\bNow listening on:\\s+(https?://\\S+)" + }, + "env": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "sourceFileMap": { + "/Views": "${workspaceFolder}/Views" + } + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/BackEnd/.vscode/tasks.json b/BackEnd/.vscode/tasks.json new file mode 100644 index 00000000..a60ac3a7 --- /dev/null +++ b/BackEnd/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/Timeline/Timeline.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/Timeline/Timeline.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/Timeline/Timeline.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/BackEnd/Timeline/Program.cs b/BackEnd/Timeline/Program.cs index 87e330a2..1f0f72b9 100644 --- a/BackEnd/Timeline/Program.cs +++ b/BackEnd/Timeline/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System.Resources; @@ -10,34 +11,38 @@ using Timeline.Services; namespace Timeline { - public static class Program + public static class Program + { + public static void Main(string[] args) { - public static void Main(string[] args) - { - var host = CreateWebHostBuilder(args).Build(); - - var env = host.Services.GetRequiredService(); + var host = CreateWebHostBuilder(args).Build(); - var databaseBackupService = host.Services.GetRequiredService(); - databaseBackupService.BackupNow(); + var env = host.Services.GetRequiredService(); - if (env.IsProduction()) - { - using (var scope = host.Services.CreateScope()) - { - var databaseContext = scope.ServiceProvider.GetRequiredService(); - databaseContext.Database.Migrate(); - } - } + var databaseBackupService = host.Services.GetRequiredService(); + databaseBackupService.BackupNow(); - host.Run(); + if (env.IsProduction()) + { + using (var scope = host.Services.CreateScope()) + { + var databaseContext = scope.ServiceProvider.GetRequiredService(); + databaseContext.Database.Migrate(); } + } - public static IHostBuilder CreateWebHostBuilder(string[] args) => - Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup(); - }); + host.Run(); } + + public static IHostBuilder CreateWebHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureAppConfiguration(config => + { + config.AddEnvironmentVariables("Timeline_"); + }) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } } diff --git a/BackEnd/Timeline/Properties/launchSettings.json b/BackEnd/Timeline/Properties/launchSettings.json index a31485ed..db58cd31 100644 --- a/BackEnd/Timeline/Properties/launchSettings.json +++ b/BackEnd/Timeline/Properties/launchSettings.json @@ -5,23 +5,20 @@ "applicationUrl": "http://0.0.0.0:5000", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", - "ASPNETCORE_FRONTEND": "Proxy", - "ASPNETCORE_WORKDIR": "D:\\timeline-development" + "ASPNETCORE_FRONTEND": "Proxy" } }, "Dev-Mock": { "commandName": "Project", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", - "ASPNETCORE_FRONTEND": "Mock", - "ASPNETCORE_WORKDIR": "D:\\timeline-development" + "ASPNETCORE_FRONTEND": "Mock" } }, "Staging": { "commandName": "Project", "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Staging", - "ASPNETCORE_WORKDIR": "D:\\timeline-development" + "ASPNETCORE_ENVIRONMENT": "Staging" } } } -- cgit v1.2.3