let user know working directory will be used as content root path by default (#82445)
authorBadre BSAILA <54767641+pedrobsaila@users.noreply.github.com>
Wed, 26 Apr 2023 19:39:02 +0000 (21:39 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Apr 2023 19:39:02 +0000 (14:39 -0500)
src/libraries/Microsoft.Extensions.Hosting/src/Internal/ConsoleLifetime.cs

index 372a614..5f23099 100644 (file)
@@ -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,13 @@ namespace Microsoft.Extensions.Hosting.Internal
             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 (contentRootFullPath.Equals(System.Environment.CurrentDirectory, StringComparison.Ordinal)
+                || contentRootFullPath.Equals(AppContext.BaseDirectory, StringComparison.Ordinal))
+            {
+                Logger.LogInformation("Current working directory is /. If Content root path is not set explicitly, then working directory is used by default.");
+            }
         }
 
         private void OnApplicationStopping()