-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
let user know working directory will be used as content root path by default #82445
Conversation
@@ -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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Path.GetFullPath(".")
Envrionment.CurrentDirectory?
InvariantCultureIgnoreCase
wrong on unix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Envrionment.CurrentDirectory ?
Envrionment.CurrentDirectory when !DisableDefaults, and AppContext.BaseDirectory elsewhere
wrong on unix?
This project uses OrdinalIgnoreCase for string comparison so I'm using Ordinal to be unix compliant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be logged as info instead?
Some apps do not care about content root and would now need to explicitly configure it anyways or add extra logging config just to avoid that this warning pollutes observability systems.
Tagging subscribers to this area: @dotnet/area-extensions-hosting Issue DetailsFixes #78789
|
string contentRootFullPath = Path.GetFullPath(Environment.ContentRootPath); | ||
|
||
if (contentRootFullPath.Equals(System.Environment.CurrentDirectory, StringComparison.Ordinal) | ||
|| contentRootFullPath.Equals(AppContext.BaseDirectory, StringComparison.Ordinal)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When are these different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
when DisableDefaults == false, it is System.Environment.CurrentDirectory :
- code :
runtime/src/libraries/Microsoft.Extensions.Hosting/src/HostingHostBuilderExtensions.cs
Lines 216 to 227 in d3f7d59
// In my testing, both Environment.CurrentDirectory and Environment.GetFolderPath(Environment.SpecialFolder.System) return the path without | |
// any trailing directory separator characters. I'm not even sure the casing can ever be different from these APIs, but I think it makes sense to | |
// ignore case for Windows path comparisons given the file system is usually (always?) going to be case insensitive for the system path. | |
string cwd = Environment.CurrentDirectory; | |
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || !string.Equals(cwd, Environment.GetFolderPath(Environment.SpecialFolder.System), StringComparison.OrdinalIgnoreCase)) | |
{ | |
hostConfigBuilder.AddInMemoryCollection(new[] | |
{ | |
new KeyValuePair<string, string?>(HostDefaults.ContentRootKey, cwd), | |
}); | |
} | |
} |
- test :
-
else it is AppContext.BaseDirectory :
- code :
runtime/src/libraries/Microsoft.Extensions.Hosting/src/HostBuilder.cs
Lines 230 to 234 in d3f7d59
var hostingEnvironment = new HostingEnvironment() | |
{ | |
EnvironmentName = hostConfiguration[HostDefaults.EnvironmentKey] ?? Environments.Production, | |
ContentRootPath = ResolveContentRootPath(hostConfiguration[HostDefaults.ContentRootKey], AppContext.BaseDirectory), | |
}; |
- test :
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if there's a case when they have different values, but the two seems different by looking at their code
/azp run runtime-dev-innerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
There are a few CI errors; re-running |
/azp run runtime |
Azure Pipelines successfully started running 1 pipeline(s). |
…path by default (dotnet#82445)" This reverts commit c958573.
@pedrobsaila there were concerns with this expressed in #85809. Please see that issue. Thanks. |
Fixes #78789