From e04954832b562a31783607cd45602149a9663ce0 Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Tue, 21 Feb 2023 20:40:52 +0100 Subject: [PATCH 1/3] let user know working directory will be used as content root path by default --- .../src/Internal/ConsoleLifetime.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs b/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs index 372a6146c55d25..50787ec2b95797 100644 --- a/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs +++ b/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.IO; using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; @@ -79,6 +80,11 @@ private void OnApplicationStarted() Logger.LogInformation("Application started. Press Ctrl+C to shut down."); Logger.LogInformation("Hosting environment: {EnvName}", Environment.EnvironmentName); Logger.LogInformation("Content root path: {ContentRoot}", Environment.ContentRootPath); + + if (Path.GetFullPath(Environment.ContentRootPath).Equals(Path.GetFullPath("."), StringComparison.InvariantCultureIgnoreCase)) + { + Logger.LogWarning("Current working directory is /. If Content root path is not set explicitly, then working directory is used by default."); + } } private void OnApplicationStopping() From 292a010c2b2e54dafb234b5db930c9167885ef2d Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Wed, 22 Feb 2023 07:29:41 +0100 Subject: [PATCH 2/3] explicit the possible default values of ContentRootPath --- .../src/Internal/ConsoleLifetime.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs b/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs index 50787ec2b95797..3bcc3127d3d5f6 100644 --- a/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs +++ b/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs @@ -80,8 +80,10 @@ private void OnApplicationStarted() Logger.LogInformation("Application started. Press Ctrl+C to shut down."); Logger.LogInformation("Hosting environment: {EnvName}", Environment.EnvironmentName); Logger.LogInformation("Content root path: {ContentRoot}", Environment.ContentRootPath); + string contentRootFullPath = Path.GetFullPath(Environment.ContentRootPath); - if (Path.GetFullPath(Environment.ContentRootPath).Equals(Path.GetFullPath("."), StringComparison.InvariantCultureIgnoreCase)) + if (contentRootFullPath.Equals(System.Environment.CurrentDirectory, StringComparison.Ordinal) + || contentRootFullPath.Equals(AppContext.BaseDirectory, StringComparison.Ordinal)) { Logger.LogWarning("Current working directory is /. If Content root path is not set explicitly, then working directory is used by default."); } From 3c557aeb6b6249067d47af748174741b55ed8f6b Mon Sep 17 00:00:00 2001 From: pedrobsaila Date: Wed, 22 Feb 2023 19:16:19 +0100 Subject: [PATCH 3/3] make logger level info --- .../src/Internal/ConsoleLifetime.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs b/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs index 3bcc3127d3d5f6..5f23099082cbfe 100644 --- a/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs +++ b/src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs @@ -85,7 +85,7 @@ private void OnApplicationStarted() if (contentRootFullPath.Equals(System.Environment.CurrentDirectory, StringComparison.Ordinal) || contentRootFullPath.Equals(AppContext.BaseDirectory, StringComparison.Ordinal)) { - Logger.LogWarning("Current working directory is /. If Content root path is not set explicitly, then working directory is used by default."); + Logger.LogInformation("Current working directory is /. If Content root path is not set explicitly, then working directory is used by default."); } }