Skip to content
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

Explictily log working directory and let user know it will be used as content root path by default. #78789

Open
1 task done
voroninp opened this issue Nov 22, 2022 · 11 comments · Fixed by #82445
Open
1 task done
Labels
area-Extensions-Hosting help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@voroninp
Copy link

voroninp commented Nov 22, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

It's not the first time I making same mistake of starting published asp.net core application in docker without setting working directory:

ENTRYPOINT ["dotnet", "/app/api.dll"]

And content root path becomes /, so appsettings and other content files are not found. This causes app to fail on startup.

Host logs its content root path much later, so in case of failure I do not get a message like:

Content root path: /app

Describe the solution you'd like

IMO, if host logged current working directory it would be much friendlier to the developer:

Current working directory is /. If Content root path is not set explicitly, then working directory is ued by default.

Additional context

No response

@BrennanConroy BrennanConroy transferred this issue from dotnet/aspnetcore Nov 23, 2022
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Nov 23, 2022
@BrennanConroy
Copy link
Member

We might be able to log this sooner, e.g. between ConfigureHostConfiguration and ConfigureAppConfiguration.

It also should be easy to add this to your app by adding a Console.WriteLine(host.Environment.ContentRoot); inside ConfigureAppConfiguration or before WebApplicationBuilder.Build(); depending on the host you're using.

@voroninp
Copy link
Author

It also should be easy to add this to your app

One should know Content Root is affected by working directory to want it to be logged. ;-)

@ghost
Copy link

ghost commented Nov 25, 2022

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

It's not the first time I making same mistake of starting published asp.net core application in docer without setting working directory:

ENTRYPOINT ["dotnet", "/app/api.dll"]

And content root path becomes /, so appsettings and other content files are not found. This causes app to fail on startup.

Host logs its content root path much later, so in case of failure I do not get a message like:

Content root path: /app

Describe the solution you'd like

IMO, if host logged current working directory it would be much friendlier to the developer:

Current working directory is /. If Content root path is not set explicitly, then working directory is ued by default.

Additional context

No response

Author: voroninp
Assignees: -
Labels:

untriaged, area-Extensions-Configuration

Milestone: -

@ghost
Copy link

ghost commented Nov 25, 2022

Tagging subscribers to this area: @dotnet/area-extensions-hosting
See info in area-owners.md if you want to be subscribed.

Issue Details

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

It's not the first time I making same mistake of starting published asp.net core application in docer without setting working directory:

ENTRYPOINT ["dotnet", "/app/api.dll"]

And content root path becomes /, so appsettings and other content files are not found. This causes app to fail on startup.

Host logs its content root path much later, so in case of failure I do not get a message like:

Content root path: /app

Describe the solution you'd like

IMO, if host logged current working directory it would be much friendlier to the developer:

Current working directory is /. If Content root path is not set explicitly, then working directory is ued by default.

Additional context

No response

Author: voroninp
Assignees: -
Labels:

untriaged, area-Extensions-Hosting

Milestone: -

@buyaa-n buyaa-n added this to the Future milestone Dec 12, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Dec 12, 2022
@buyaa-n buyaa-n added the help wanted [up-for-grabs] Good issue for external contributors label Dec 12, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Feb 21, 2023
@tmds
Copy link
Member

tmds commented Feb 23, 2023

I'm not sure what the design rationale was for making the ContentRoot default to the working directory?

This breaks apps that depend on files that sit besides the app, like appsettings or Razor files.

hostBuilder.UseContentRoot(AppContext.BaseDirectory)

makes the problem disappear.

Note: the content root can also be set using the DOTNET_CONTENTROOT envvar.

@voroninp
Copy link
Author

@tmds , this should be in project template, IMO.

@tmds
Copy link
Member

tmds commented Feb 28, 2023

@davidfowl do you know why ContentRoot defaults to the working directory?

Any thoughts on including:

hostBuilder.UseContentRoot(AppContext.BaseDirectory)

in the templates?

@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Apr 26, 2023
@steveharter steveharter reopened this May 10, 2023
@steveharter
Copy link
Member

The previous merge was reverted due to concerns in #85809 which need to be addressed for the next go.

@pedrobsaila
Copy link
Contributor

pedrobsaila commented May 11, 2023

@steveharter the concerns varied from don't need this log at all to we can keep it with adjustments. So what is the target here ?

In case we take the adjustment road, I'm not convinced at all with making the log level Debug, it's rare that someone launches an application with this min log level : from what I see in the community, we configure min log level as Information for Debug/Development environments and Warning/Error is used for integration/test/production environments. Downgrading to Debug means that no one will ever see it making it useless.

@tmds
Copy link
Member

tmds commented May 11, 2023

The underlying issue is that ASP.NET apps that come with content files (like Razor pages and appsettings files), the files are published with the app, but the app goes looking for them in the working directory.
So when you start the app from a random directory, it doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Extensions-Hosting help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants