weixin_39681058
weixin_39681058
2020-12-28 12:15

Calls to WebHost.CreateDefaultBuilder override the ASPNETCORE_CONTENTROOT environment variable

From -Bonner on February 24, 2018 8:47

See javiercn's comments:

This might be an integration bug. You should be able to change the content root by doing setting the ASPNETCORE_CONTENTROOT environment variable, but I believe that calling UseContentRoot override that.

Hosting just reads the content root from a setting in the host configuration. By default, hosting adds environment variables to the configuration and the call to UseContentRoot adds an in memory collection to the configuration after the environment variables, which I believe it means that value overrides the environment variable.

Given those two things together I think using CreateDefaultBuilder prevents you from using an environment variable to configure the content root, and that can be considered a bug, but I'll leave it to .

Copied from: https://github.com/aspnet/Home/issues/2897#issuecomment-368148258

Copied from original issue: aspnet/Home#2901

该提问来源于开源项目:aspnet/Hosting

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • weixin_39932939 weixin_39932939 4月前

    Hi
    I have a minimal repro for this issue : https://github.com/rducom/ContentRootRepro/tree/master

    This is blocking using WebApplicationFactory in IClassFixture on aspnet core 2.1.2 when the test project is in a /test/ folder

    I hope you can reopen the issue.

    I didn't manage to find a workaround, so If you have an idea, you're welcome 😃

    点赞 评论 复制链接分享
  • weixin_39681058 weixin_39681058 4月前

    Re-opening so that this can be examined again.

    点赞 评论 复制链接分享
  • weixin_39528843 weixin_39528843 4月前

    Duplicate of https://github.com/aspnet/MetaPackages/issues/267, fixed in 2.2: https://github.com/aspnet/MetaPackages/commit/48a9013e089a8d15a3314c83e14679d789fd894d

    点赞 评论 复制链接分享
  • weixin_39932939 weixin_39932939 4月前

    Thanks !

    点赞 评论 复制链接分享
  • weixin_39681058 weixin_39681058 4月前

    safe to close again?

    点赞 评论 复制链接分享
  • weixin_39681058 weixin_39681058 4月前

    From -Bonner on February 24, 2018 11:20

    After testing it looks like you don't even need to call UseContentRoot in CreateDefaultBuilder. Can someone confirm this for *nix and mac?

    点赞 评论 复制链接分享
  • weixin_39662834 weixin_39662834 4月前

    I don't remember why we set content root in CreateDefaultBuilder. I want to say that we did it explicitly, but can't remember in what scenarios it ends up being wrong if we don't. Can either of you?

    点赞 评论 复制链接分享
  • weixin_39781550 weixin_39781550 4月前

    Hi. We're closing this issue as no response or updates have been provided in a timely manner and we have been unable to reproduce it. If you have more details and are encountering this issue please add a new reply and re-open the issue.

    点赞 评论 复制链接分享