Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2017 在ASP.NET Core中使用自定义环境_Visual Studio 2017_Environment Variables - Fatal编程技术网

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

Visual studio 2017 在ASP.NET Core中使用自定义环境,visual-studio-2017,environment-variables,Visual Studio 2017,Environment Variables,我的appsettings文件确实有效我看到它们是根据我使用的启动配置文件使用的,但是我的localhost配置文件不起作用,因为它似乎不存在于我使用的实际框架中。是否仍要添加自定义的,如“localhost” 编辑: 谢谢 在Program.cs中,添加对config.AddJsonFile()的调用: publicstaticvoidmain(字符串[]args) { CreateWebHostBuilder(args.Build().Run(); } 公共静态IWebHostBuil

我的appsettings文件确实有效我看到它们是根据我使用的启动配置文件使用的,但是我的localhost配置文件不起作用,因为它似乎不存在于我使用的实际框架中。是否仍要添加自定义的,如“localhost”

编辑:


谢谢

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

publicstaticvoidmain(字符串[]args)
{
CreateWebHostBuilder(args.Build().Run();
}
公共静态IWebHostBuilder CreateWebHostBuilder(字符串[]args)=>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext,config)=>
{
config.AddJsonFile(“appsettings.Localhost.json”,可选:true);
})
.UseStartup();
    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>();