visual-studio-2017 - 在 ASP.NET Core 中使用自定义环境

标签 visual-studio-2017 environment-variables

我的 appsettings 文件确实有效,我看到它们是根据我使用的启动配置文件使用的,但是我的本地主机配置文件不起作用,因为它似乎不存在于我使用的实际框架中。无论如何要添加一个自定义的,例如“本地主机”?

My appsettings files does work I see them being used according to which launching profile I use however,,,

My Localhost profile doesn't work because it doesn't seems to exist in the actual Framework I use. Is there anyway to add a custom one such as "localhost"?

编辑:

enter image description here

谢谢!

最佳答案

在您的 Program.cs 中,添加对 config.AddJsonFile() 的调用:

    public static void Main(string[] args)
    {
        CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .ConfigureAppConfiguration((hostingContext, config) =>
            {
                config.AddJsonFile("appsettings.Localhost.json", optional: true);
            })
            .UseStartup<Startup>();

关于visual-studio-2017 - 在 ASP.NET Core 中使用自定义环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54443927/

相关文章:

environment-variables - 将 CFLAGS 添加到 QMake 项目而不在 .pro 文件中对其进行硬编码?

c++ - 在 C 和 C++ 中通过编译器环境变量或命令行标志指定库路径?

visual-studio - 如何配置 Visual Studio 的测试应用程序

c# - 为什么我不能在 Visual Studio 中合并项目 sdk 版本?

debugging - WinDbg环境变量

linux - 为什么 env 不打印 PS1 变量?

c# - 在 .NET 中获取远程计算机上环境变量的实际值

visual-studio - 更新后 Visual Studio 2017 代码颜色问题

c++ - 在 Visual Studio 中 fwrite 超过 4GB

c++ - 从 VS 2017 到 VS 2012 的命名空间转换