Skip to content

ASPNETCORE_CONTENTROOT being ignored in .NET 7 #78583

@bfren

Description

@bfren

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

ASP.NET 7 is using the current working directory as content root - even if an override environment variable is set.

This is a problem using the S6 supervisor, where the current working directory is an S6 directory, not the directory containing the published files.

In ASP.NET 6, setting ASPNETCORE_CONTENTROOT forced the framework to look in the correct place - this appears to have stopped working with the release of .NET 7.

So, e.g. in printenv:

# printenv
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
HOSTNAME=eb3218af2e48
SHLVL=1
HOME=/root
DOTNET_RUNNING_IN_CONTAINER=true
S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
ASPNET_VERSION_MINOR=7.0
TERM=xterm
ASPNET_ASSEMBLY=xxxxxx.dll
ASPNETCORE_CONTENTROOT=/app/live      <-- correct value
ASPNETCORE_URLS=http://+:5000
PWD=/

But in startup logs:

[16:14:51 INF] Content root path: /run/s6-rc:s6-rc-init:amgdpf/servicedirs/aspnet

And then requesting https://xxxxxx/css/bundles/1.0/licence.min.css gives this in the log:

[17:42:55 INF] Request finished HTTP/1.0 GET /css/bundles/1.0/licence.min.css - - - 404 0 - 0.2135ms

Despite:

# ls /app/live/wwwroot/css/bundles/1.0
licence.css      licence.min.css

Expected Behavior

Setting ASPNETCORE_CONTENTROOT should override the current working directory.

Steps To Reproduce

Execute:

docker run --rm -it
  -p 8000:80 \
  -v /path/to/app:/app \
  -e ASPNETCORE_CONTENTROOT=/tmp \
  mcr.microsoft.com/dotnet/aspnet:7.0 \
  sh

Inside the container execute dotnet /path/to/app/dll.

Content root is set to /app instead of /tmp (incorrectly).

Exceptions (if any)

No response

.NET Version

7.0.0

Anything else?

dotnet --list-runtimes
Microsoft.AspNetCore.App 7.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions