ASP.NET Core 1.0 ConfigurationBuilder().AddJsonFile(“appsettings.json”); not finding file





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







27















So I've finally got round to looking at Core and I've fallen at the first hurdle. I'm following the Pluralsight ASP.NET Core Fundamentals course and I'm getting an exception when trying too add the appsettings.json file to the configuration builder.



public Startup()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json");

Configuration = builder.Build();
}


The error I'm getting is The configuration file 'appsettings.json' was not found and is not optional. But I have created the directly under my solution just like in the course video.



Any suggestions?



Cheers,










share|improve this question































    27















    So I've finally got round to looking at Core and I've fallen at the first hurdle. I'm following the Pluralsight ASP.NET Core Fundamentals course and I'm getting an exception when trying too add the appsettings.json file to the configuration builder.



    public Startup()
    {
    var builder = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json");

    Configuration = builder.Build();
    }


    The error I'm getting is The configuration file 'appsettings.json' was not found and is not optional. But I have created the directly under my solution just like in the course video.



    Any suggestions?



    Cheers,










    share|improve this question



























      27












      27








      27


      5






      So I've finally got round to looking at Core and I've fallen at the first hurdle. I'm following the Pluralsight ASP.NET Core Fundamentals course and I'm getting an exception when trying too add the appsettings.json file to the configuration builder.



      public Startup()
      {
      var builder = new ConfigurationBuilder()
      .AddJsonFile("appsettings.json");

      Configuration = builder.Build();
      }


      The error I'm getting is The configuration file 'appsettings.json' was not found and is not optional. But I have created the directly under my solution just like in the course video.



      Any suggestions?



      Cheers,










      share|improve this question
















      So I've finally got round to looking at Core and I've fallen at the first hurdle. I'm following the Pluralsight ASP.NET Core Fundamentals course and I'm getting an exception when trying too add the appsettings.json file to the configuration builder.



      public Startup()
      {
      var builder = new ConfigurationBuilder()
      .AddJsonFile("appsettings.json");

      Configuration = builder.Build();
      }


      The error I'm getting is The configuration file 'appsettings.json' was not found and is not optional. But I have created the directly under my solution just like in the course video.



      Any suggestions?



      Cheers,







      asp.net asp.net-core asp.net-core-2.0






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 6 '18 at 12:40









      Ajay2707

      4,42142345




      4,42142345










      asked Jul 9 '16 at 14:06









      ZhorianZhorian

      4971513




      4971513
























          10 Answers
          10






          active

          oldest

          votes


















          21














          public Startup(IHostingEnvironment env)
          {
          var builder = new ConfigurationBuilder()
          .SetBasePath(env.ContentRootPath)
          .AddJsonFile("appsettings.json");

          Configuration = builder.Build();
          }


          This seems to do the trick. However unsure this is the proper way to do it. Kinda feels like a hack.






          share|improve this answer



















          • 3





            I was able to get it to work using .SetBasePath(Directory.GetCurrentDirectory()), as shown here: benfoster.io/blog/…

            – Sako73
            Aug 23 '16 at 14:18






          • 1





            Well, if it IS a hack, it's a hack the Microsoft does themselves when you set up a new blank ASP.NET Core Web Application.

            – David
            Jan 6 '17 at 18:03



















          20














          You need to add the package below:



              "Microsoft.Extensions.Configuration.Json": "1.0.0"





          share|improve this answer
























          • This was what i was missing. Thanks!

            – Tadej
            Dec 6 '17 at 7:35



















          14














          Another way:



          appsettings.json:



          {
          "greeting": "A configurable hello, to you!"
          }


          Startup.cs:



          using Microsoft.Extensions.Configuration; // for using IConfiguration
          using System.IO; // for using Directory

          public class Startup
          {
          public IConfiguration Configuration { get; set; }

          public Startup()
          {
          var builder = new ConfigurationBuilder();
          builder.SetBasePath(Directory.GetCurrentDirectory());
          builder.AddJsonFile("appsettings.json");

          Configuration = builder.Build();
          }
          }


          In the Configure method:



          app.Run(async (context) =>
          {
          // Don't use:
          // string greeting = Configuration["greeting"]; // null

          string greeting = Configuration.GetSection("greeting").Value;
          await context.Response.WriteAsync(greeting)
          });





          share|improve this answer
























          • Thank you! builder.SetBasePath(Directory.GetCurrentDirectory()); fixed it for me.

            – w0ns88
            Dec 11 '18 at 9:18



















          9














          An alternative solution I found from this blog post works as well. It has the added benefit of not needing to modify the Startup.cs file's Startup method signature.




          In the buildOptions section add copyToOutput with the name of the file.




          {
          "version": "1.0.0-*",
          "buildOptions": {
          "emitEntryPoint": true,
          "copyToOutput": "appsettings.json"
          },
          .... The rest of the file goes here ....





          share|improve this answer
























          • If you don't have project.json; don't worry. It is dumped, more detail on here

            – Beytan Kurt
            Aug 1 '18 at 12:49





















          6














          Actually for this you need to provide provide root path from your environment variable so you need to pass IHostingEnvironment reference to provide root path:



          public Startup(IHostingEnvironment env)
          {
          var builder = new ConfigurationBuilder()
          .SetBasePath(env.ContentRootPath)
          .AddJsonFile("appsettings.json");
          Configuration = builder.Build();
          }


          and if you can't find AddJsonFile method then you have to add using Microsoft.Extensions.Configuration.Json;






          share|improve this answer

































            3














            In .NET Core 2.0, you would update the .csproj file to copy the JSON file to the output directory so that it can be accessed, like so:



            <ItemGroup>
            <Folder Include="wwwroot" />
            <None Include="appsettings.json" CopyToOutputDirectory="Always" />
            </ItemGroup>





            share|improve this answer
























            • Thank you a lot!

              – Vitaliy
              Jun 12 '18 at 12:50



















            2














            Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"






            share|improve this answer































              1














              The answers that suggest adding .SetBasePath(env.ContentRootPath) in Startup.cs depend upon a prior step.



              First, add the line .UseContentRoot(Directory.GetCurrentDirectory()) to your WebHostBuilder construction in Program.cs like so:



              public class Program
              {
              public static void Main(string args)
              {
              var config = new ConfigurationBuilder()
              .SetBasePath(Directory.GetCurrentDirectory())
              .AddEnvironmentVariables()
              .Build();

              var host = new WebHostBuilder()
              .UseConfiguration(config)
              .UseKestrel()
              .UseContentRoot(Directory.GetCurrentDirectory())
              .UseStartup<Startup>()
              .Build();

              host.Run();
              }
              }


              Then the following will work:



              public Startup(IHostingEnvironment env)
              {
              var builder = new ConfigurationBuilder()
              .SetBasePath(env.ContentRootPath)
              .AddJsonFile("appsettings.json");

              Configuration = builder.Build();
              }





              share|improve this answer































                0














                If you have done anything with Project Debug Properties, then you may have inadvertently overwritten the starting directory:



                Project -> Right-click -> Properties -> Debug -> Profile and then look at the entry in Working Directory.



                The simplest is that it be blank.






                share|improve this answer































                  0














                  You Need to istall Configuration.Json package from Microsoft.Extensions
                  or just add Microsoft.Extensions.Configuration.Json to y






                  share|improve this answer


























                    Your Answer






                    StackExchange.ifUsing("editor", function () {
                    StackExchange.using("externalEditor", function () {
                    StackExchange.using("snippets", function () {
                    StackExchange.snippets.init();
                    });
                    });
                    }, "code-snippets");

                    StackExchange.ready(function() {
                    var channelOptions = {
                    tags: "".split(" "),
                    id: "1"
                    };
                    initTagRenderer("".split(" "), "".split(" "), channelOptions);

                    StackExchange.using("externalEditor", function() {
                    // Have to fire editor after snippets, if snippets enabled
                    if (StackExchange.settings.snippets.snippetsEnabled) {
                    StackExchange.using("snippets", function() {
                    createEditor();
                    });
                    }
                    else {
                    createEditor();
                    }
                    });

                    function createEditor() {
                    StackExchange.prepareEditor({
                    heartbeatType: 'answer',
                    autoActivateHeartbeat: false,
                    convertImagesToLinks: true,
                    noModals: true,
                    showLowRepImageUploadWarning: true,
                    reputationToPostImages: 10,
                    bindNavPrevention: true,
                    postfix: "",
                    imageUploader: {
                    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                    allowUrls: true
                    },
                    onDemand: true,
                    discardSelector: ".discard-answer"
                    ,immediatelyShowMarkdownHelp:true
                    });


                    }
                    });














                    draft saved

                    draft discarded


















                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38282652%2fasp-net-core-1-0-configurationbuilder-addjsonfileappsettings-json-not-fin%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown

























                    10 Answers
                    10






                    active

                    oldest

                    votes








                    10 Answers
                    10






                    active

                    oldest

                    votes









                    active

                    oldest

                    votes






                    active

                    oldest

                    votes









                    21














                    public Startup(IHostingEnvironment env)
                    {
                    var builder = new ConfigurationBuilder()
                    .SetBasePath(env.ContentRootPath)
                    .AddJsonFile("appsettings.json");

                    Configuration = builder.Build();
                    }


                    This seems to do the trick. However unsure this is the proper way to do it. Kinda feels like a hack.






                    share|improve this answer



















                    • 3





                      I was able to get it to work using .SetBasePath(Directory.GetCurrentDirectory()), as shown here: benfoster.io/blog/…

                      – Sako73
                      Aug 23 '16 at 14:18






                    • 1





                      Well, if it IS a hack, it's a hack the Microsoft does themselves when you set up a new blank ASP.NET Core Web Application.

                      – David
                      Jan 6 '17 at 18:03
















                    21














                    public Startup(IHostingEnvironment env)
                    {
                    var builder = new ConfigurationBuilder()
                    .SetBasePath(env.ContentRootPath)
                    .AddJsonFile("appsettings.json");

                    Configuration = builder.Build();
                    }


                    This seems to do the trick. However unsure this is the proper way to do it. Kinda feels like a hack.






                    share|improve this answer



















                    • 3





                      I was able to get it to work using .SetBasePath(Directory.GetCurrentDirectory()), as shown here: benfoster.io/blog/…

                      – Sako73
                      Aug 23 '16 at 14:18






                    • 1





                      Well, if it IS a hack, it's a hack the Microsoft does themselves when you set up a new blank ASP.NET Core Web Application.

                      – David
                      Jan 6 '17 at 18:03














                    21












                    21








                    21







                    public Startup(IHostingEnvironment env)
                    {
                    var builder = new ConfigurationBuilder()
                    .SetBasePath(env.ContentRootPath)
                    .AddJsonFile("appsettings.json");

                    Configuration = builder.Build();
                    }


                    This seems to do the trick. However unsure this is the proper way to do it. Kinda feels like a hack.






                    share|improve this answer













                    public Startup(IHostingEnvironment env)
                    {
                    var builder = new ConfigurationBuilder()
                    .SetBasePath(env.ContentRootPath)
                    .AddJsonFile("appsettings.json");

                    Configuration = builder.Build();
                    }


                    This seems to do the trick. However unsure this is the proper way to do it. Kinda feels like a hack.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 9 '16 at 14:16









                    ZhorianZhorian

                    4971513




                    4971513








                    • 3





                      I was able to get it to work using .SetBasePath(Directory.GetCurrentDirectory()), as shown here: benfoster.io/blog/…

                      – Sako73
                      Aug 23 '16 at 14:18






                    • 1





                      Well, if it IS a hack, it's a hack the Microsoft does themselves when you set up a new blank ASP.NET Core Web Application.

                      – David
                      Jan 6 '17 at 18:03














                    • 3





                      I was able to get it to work using .SetBasePath(Directory.GetCurrentDirectory()), as shown here: benfoster.io/blog/…

                      – Sako73
                      Aug 23 '16 at 14:18






                    • 1





                      Well, if it IS a hack, it's a hack the Microsoft does themselves when you set up a new blank ASP.NET Core Web Application.

                      – David
                      Jan 6 '17 at 18:03








                    3




                    3





                    I was able to get it to work using .SetBasePath(Directory.GetCurrentDirectory()), as shown here: benfoster.io/blog/…

                    – Sako73
                    Aug 23 '16 at 14:18





                    I was able to get it to work using .SetBasePath(Directory.GetCurrentDirectory()), as shown here: benfoster.io/blog/…

                    – Sako73
                    Aug 23 '16 at 14:18




                    1




                    1





                    Well, if it IS a hack, it's a hack the Microsoft does themselves when you set up a new blank ASP.NET Core Web Application.

                    – David
                    Jan 6 '17 at 18:03





                    Well, if it IS a hack, it's a hack the Microsoft does themselves when you set up a new blank ASP.NET Core Web Application.

                    – David
                    Jan 6 '17 at 18:03













                    20














                    You need to add the package below:



                        "Microsoft.Extensions.Configuration.Json": "1.0.0"





                    share|improve this answer
























                    • This was what i was missing. Thanks!

                      – Tadej
                      Dec 6 '17 at 7:35
















                    20














                    You need to add the package below:



                        "Microsoft.Extensions.Configuration.Json": "1.0.0"





                    share|improve this answer
























                    • This was what i was missing. Thanks!

                      – Tadej
                      Dec 6 '17 at 7:35














                    20












                    20








                    20







                    You need to add the package below:



                        "Microsoft.Extensions.Configuration.Json": "1.0.0"





                    share|improve this answer













                    You need to add the package below:



                        "Microsoft.Extensions.Configuration.Json": "1.0.0"






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 29 '16 at 20:51









                    user6655970user6655970

                    20114




                    20114













                    • This was what i was missing. Thanks!

                      – Tadej
                      Dec 6 '17 at 7:35



















                    • This was what i was missing. Thanks!

                      – Tadej
                      Dec 6 '17 at 7:35

















                    This was what i was missing. Thanks!

                    – Tadej
                    Dec 6 '17 at 7:35





                    This was what i was missing. Thanks!

                    – Tadej
                    Dec 6 '17 at 7:35











                    14














                    Another way:



                    appsettings.json:



                    {
                    "greeting": "A configurable hello, to you!"
                    }


                    Startup.cs:



                    using Microsoft.Extensions.Configuration; // for using IConfiguration
                    using System.IO; // for using Directory

                    public class Startup
                    {
                    public IConfiguration Configuration { get; set; }

                    public Startup()
                    {
                    var builder = new ConfigurationBuilder();
                    builder.SetBasePath(Directory.GetCurrentDirectory());
                    builder.AddJsonFile("appsettings.json");

                    Configuration = builder.Build();
                    }
                    }


                    In the Configure method:



                    app.Run(async (context) =>
                    {
                    // Don't use:
                    // string greeting = Configuration["greeting"]; // null

                    string greeting = Configuration.GetSection("greeting").Value;
                    await context.Response.WriteAsync(greeting)
                    });





                    share|improve this answer
























                    • Thank you! builder.SetBasePath(Directory.GetCurrentDirectory()); fixed it for me.

                      – w0ns88
                      Dec 11 '18 at 9:18
















                    14














                    Another way:



                    appsettings.json:



                    {
                    "greeting": "A configurable hello, to you!"
                    }


                    Startup.cs:



                    using Microsoft.Extensions.Configuration; // for using IConfiguration
                    using System.IO; // for using Directory

                    public class Startup
                    {
                    public IConfiguration Configuration { get; set; }

                    public Startup()
                    {
                    var builder = new ConfigurationBuilder();
                    builder.SetBasePath(Directory.GetCurrentDirectory());
                    builder.AddJsonFile("appsettings.json");

                    Configuration = builder.Build();
                    }
                    }


                    In the Configure method:



                    app.Run(async (context) =>
                    {
                    // Don't use:
                    // string greeting = Configuration["greeting"]; // null

                    string greeting = Configuration.GetSection("greeting").Value;
                    await context.Response.WriteAsync(greeting)
                    });





                    share|improve this answer
























                    • Thank you! builder.SetBasePath(Directory.GetCurrentDirectory()); fixed it for me.

                      – w0ns88
                      Dec 11 '18 at 9:18














                    14












                    14








                    14







                    Another way:



                    appsettings.json:



                    {
                    "greeting": "A configurable hello, to you!"
                    }


                    Startup.cs:



                    using Microsoft.Extensions.Configuration; // for using IConfiguration
                    using System.IO; // for using Directory

                    public class Startup
                    {
                    public IConfiguration Configuration { get; set; }

                    public Startup()
                    {
                    var builder = new ConfigurationBuilder();
                    builder.SetBasePath(Directory.GetCurrentDirectory());
                    builder.AddJsonFile("appsettings.json");

                    Configuration = builder.Build();
                    }
                    }


                    In the Configure method:



                    app.Run(async (context) =>
                    {
                    // Don't use:
                    // string greeting = Configuration["greeting"]; // null

                    string greeting = Configuration.GetSection("greeting").Value;
                    await context.Response.WriteAsync(greeting)
                    });





                    share|improve this answer













                    Another way:



                    appsettings.json:



                    {
                    "greeting": "A configurable hello, to you!"
                    }


                    Startup.cs:



                    using Microsoft.Extensions.Configuration; // for using IConfiguration
                    using System.IO; // for using Directory

                    public class Startup
                    {
                    public IConfiguration Configuration { get; set; }

                    public Startup()
                    {
                    var builder = new ConfigurationBuilder();
                    builder.SetBasePath(Directory.GetCurrentDirectory());
                    builder.AddJsonFile("appsettings.json");

                    Configuration = builder.Build();
                    }
                    }


                    In the Configure method:



                    app.Run(async (context) =>
                    {
                    // Don't use:
                    // string greeting = Configuration["greeting"]; // null

                    string greeting = Configuration.GetSection("greeting").Value;
                    await context.Response.WriteAsync(greeting)
                    });






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Sep 15 '16 at 12:34









                    FooFoo

                    1




                    1













                    • Thank you! builder.SetBasePath(Directory.GetCurrentDirectory()); fixed it for me.

                      – w0ns88
                      Dec 11 '18 at 9:18



















                    • Thank you! builder.SetBasePath(Directory.GetCurrentDirectory()); fixed it for me.

                      – w0ns88
                      Dec 11 '18 at 9:18

















                    Thank you! builder.SetBasePath(Directory.GetCurrentDirectory()); fixed it for me.

                    – w0ns88
                    Dec 11 '18 at 9:18





                    Thank you! builder.SetBasePath(Directory.GetCurrentDirectory()); fixed it for me.

                    – w0ns88
                    Dec 11 '18 at 9:18











                    9














                    An alternative solution I found from this blog post works as well. It has the added benefit of not needing to modify the Startup.cs file's Startup method signature.




                    In the buildOptions section add copyToOutput with the name of the file.




                    {
                    "version": "1.0.0-*",
                    "buildOptions": {
                    "emitEntryPoint": true,
                    "copyToOutput": "appsettings.json"
                    },
                    .... The rest of the file goes here ....





                    share|improve this answer
























                    • If you don't have project.json; don't worry. It is dumped, more detail on here

                      – Beytan Kurt
                      Aug 1 '18 at 12:49


















                    9














                    An alternative solution I found from this blog post works as well. It has the added benefit of not needing to modify the Startup.cs file's Startup method signature.




                    In the buildOptions section add copyToOutput with the name of the file.




                    {
                    "version": "1.0.0-*",
                    "buildOptions": {
                    "emitEntryPoint": true,
                    "copyToOutput": "appsettings.json"
                    },
                    .... The rest of the file goes here ....





                    share|improve this answer
























                    • If you don't have project.json; don't worry. It is dumped, more detail on here

                      – Beytan Kurt
                      Aug 1 '18 at 12:49
















                    9












                    9








                    9







                    An alternative solution I found from this blog post works as well. It has the added benefit of not needing to modify the Startup.cs file's Startup method signature.




                    In the buildOptions section add copyToOutput with the name of the file.




                    {
                    "version": "1.0.0-*",
                    "buildOptions": {
                    "emitEntryPoint": true,
                    "copyToOutput": "appsettings.json"
                    },
                    .... The rest of the file goes here ....





                    share|improve this answer













                    An alternative solution I found from this blog post works as well. It has the added benefit of not needing to modify the Startup.cs file's Startup method signature.




                    In the buildOptions section add copyToOutput with the name of the file.




                    {
                    "version": "1.0.0-*",
                    "buildOptions": {
                    "emitEntryPoint": true,
                    "copyToOutput": "appsettings.json"
                    },
                    .... The rest of the file goes here ....






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 25 '16 at 15:55









                    DzejmsDzejms

                    1,46812035




                    1,46812035













                    • If you don't have project.json; don't worry. It is dumped, more detail on here

                      – Beytan Kurt
                      Aug 1 '18 at 12:49





















                    • If you don't have project.json; don't worry. It is dumped, more detail on here

                      – Beytan Kurt
                      Aug 1 '18 at 12:49



















                    If you don't have project.json; don't worry. It is dumped, more detail on here

                    – Beytan Kurt
                    Aug 1 '18 at 12:49







                    If you don't have project.json; don't worry. It is dumped, more detail on here

                    – Beytan Kurt
                    Aug 1 '18 at 12:49













                    6














                    Actually for this you need to provide provide root path from your environment variable so you need to pass IHostingEnvironment reference to provide root path:



                    public Startup(IHostingEnvironment env)
                    {
                    var builder = new ConfigurationBuilder()
                    .SetBasePath(env.ContentRootPath)
                    .AddJsonFile("appsettings.json");
                    Configuration = builder.Build();
                    }


                    and if you can't find AddJsonFile method then you have to add using Microsoft.Extensions.Configuration.Json;






                    share|improve this answer






























                      6














                      Actually for this you need to provide provide root path from your environment variable so you need to pass IHostingEnvironment reference to provide root path:



                      public Startup(IHostingEnvironment env)
                      {
                      var builder = new ConfigurationBuilder()
                      .SetBasePath(env.ContentRootPath)
                      .AddJsonFile("appsettings.json");
                      Configuration = builder.Build();
                      }


                      and if you can't find AddJsonFile method then you have to add using Microsoft.Extensions.Configuration.Json;






                      share|improve this answer




























                        6












                        6








                        6







                        Actually for this you need to provide provide root path from your environment variable so you need to pass IHostingEnvironment reference to provide root path:



                        public Startup(IHostingEnvironment env)
                        {
                        var builder = new ConfigurationBuilder()
                        .SetBasePath(env.ContentRootPath)
                        .AddJsonFile("appsettings.json");
                        Configuration = builder.Build();
                        }


                        and if you can't find AddJsonFile method then you have to add using Microsoft.Extensions.Configuration.Json;






                        share|improve this answer















                        Actually for this you need to provide provide root path from your environment variable so you need to pass IHostingEnvironment reference to provide root path:



                        public Startup(IHostingEnvironment env)
                        {
                        var builder = new ConfigurationBuilder()
                        .SetBasePath(env.ContentRootPath)
                        .AddJsonFile("appsettings.json");
                        Configuration = builder.Build();
                        }


                        and if you can't find AddJsonFile method then you have to add using Microsoft.Extensions.Configuration.Json;







                        share|improve this answer














                        share|improve this answer



                        share|improve this answer








                        edited Jul 20 '17 at 11:44









                        Cyril Durand

                        9,96443240




                        9,96443240










                        answered Oct 24 '16 at 12:38









                        bhatt raviibhatt ravii

                        362312




                        362312























                            3














                            In .NET Core 2.0, you would update the .csproj file to copy the JSON file to the output directory so that it can be accessed, like so:



                            <ItemGroup>
                            <Folder Include="wwwroot" />
                            <None Include="appsettings.json" CopyToOutputDirectory="Always" />
                            </ItemGroup>





                            share|improve this answer
























                            • Thank you a lot!

                              – Vitaliy
                              Jun 12 '18 at 12:50
















                            3














                            In .NET Core 2.0, you would update the .csproj file to copy the JSON file to the output directory so that it can be accessed, like so:



                            <ItemGroup>
                            <Folder Include="wwwroot" />
                            <None Include="appsettings.json" CopyToOutputDirectory="Always" />
                            </ItemGroup>





                            share|improve this answer
























                            • Thank you a lot!

                              – Vitaliy
                              Jun 12 '18 at 12:50














                            3












                            3








                            3







                            In .NET Core 2.0, you would update the .csproj file to copy the JSON file to the output directory so that it can be accessed, like so:



                            <ItemGroup>
                            <Folder Include="wwwroot" />
                            <None Include="appsettings.json" CopyToOutputDirectory="Always" />
                            </ItemGroup>





                            share|improve this answer













                            In .NET Core 2.0, you would update the .csproj file to copy the JSON file to the output directory so that it can be accessed, like so:



                            <ItemGroup>
                            <Folder Include="wwwroot" />
                            <None Include="appsettings.json" CopyToOutputDirectory="Always" />
                            </ItemGroup>






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 25 '18 at 23:13









                            SchattenJagerSchattenJager

                            228111




                            228111













                            • Thank you a lot!

                              – Vitaliy
                              Jun 12 '18 at 12:50



















                            • Thank you a lot!

                              – Vitaliy
                              Jun 12 '18 at 12:50

















                            Thank you a lot!

                            – Vitaliy
                            Jun 12 '18 at 12:50





                            Thank you a lot!

                            – Vitaliy
                            Jun 12 '18 at 12:50











                            2














                            Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"






                            share|improve this answer




























                              2














                              Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"






                              share|improve this answer


























                                2












                                2








                                2







                                Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"






                                share|improve this answer













                                Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jan 4 at 18:36









                                user3413723user3413723

                                4,3333440




                                4,3333440























                                    1














                                    The answers that suggest adding .SetBasePath(env.ContentRootPath) in Startup.cs depend upon a prior step.



                                    First, add the line .UseContentRoot(Directory.GetCurrentDirectory()) to your WebHostBuilder construction in Program.cs like so:



                                    public class Program
                                    {
                                    public static void Main(string args)
                                    {
                                    var config = new ConfigurationBuilder()
                                    .SetBasePath(Directory.GetCurrentDirectory())
                                    .AddEnvironmentVariables()
                                    .Build();

                                    var host = new WebHostBuilder()
                                    .UseConfiguration(config)
                                    .UseKestrel()
                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                    .UseStartup<Startup>()
                                    .Build();

                                    host.Run();
                                    }
                                    }


                                    Then the following will work:



                                    public Startup(IHostingEnvironment env)
                                    {
                                    var builder = new ConfigurationBuilder()
                                    .SetBasePath(env.ContentRootPath)
                                    .AddJsonFile("appsettings.json");

                                    Configuration = builder.Build();
                                    }





                                    share|improve this answer




























                                      1














                                      The answers that suggest adding .SetBasePath(env.ContentRootPath) in Startup.cs depend upon a prior step.



                                      First, add the line .UseContentRoot(Directory.GetCurrentDirectory()) to your WebHostBuilder construction in Program.cs like so:



                                      public class Program
                                      {
                                      public static void Main(string args)
                                      {
                                      var config = new ConfigurationBuilder()
                                      .SetBasePath(Directory.GetCurrentDirectory())
                                      .AddEnvironmentVariables()
                                      .Build();

                                      var host = new WebHostBuilder()
                                      .UseConfiguration(config)
                                      .UseKestrel()
                                      .UseContentRoot(Directory.GetCurrentDirectory())
                                      .UseStartup<Startup>()
                                      .Build();

                                      host.Run();
                                      }
                                      }


                                      Then the following will work:



                                      public Startup(IHostingEnvironment env)
                                      {
                                      var builder = new ConfigurationBuilder()
                                      .SetBasePath(env.ContentRootPath)
                                      .AddJsonFile("appsettings.json");

                                      Configuration = builder.Build();
                                      }





                                      share|improve this answer


























                                        1












                                        1








                                        1







                                        The answers that suggest adding .SetBasePath(env.ContentRootPath) in Startup.cs depend upon a prior step.



                                        First, add the line .UseContentRoot(Directory.GetCurrentDirectory()) to your WebHostBuilder construction in Program.cs like so:



                                        public class Program
                                        {
                                        public static void Main(string args)
                                        {
                                        var config = new ConfigurationBuilder()
                                        .SetBasePath(Directory.GetCurrentDirectory())
                                        .AddEnvironmentVariables()
                                        .Build();

                                        var host = new WebHostBuilder()
                                        .UseConfiguration(config)
                                        .UseKestrel()
                                        .UseContentRoot(Directory.GetCurrentDirectory())
                                        .UseStartup<Startup>()
                                        .Build();

                                        host.Run();
                                        }
                                        }


                                        Then the following will work:



                                        public Startup(IHostingEnvironment env)
                                        {
                                        var builder = new ConfigurationBuilder()
                                        .SetBasePath(env.ContentRootPath)
                                        .AddJsonFile("appsettings.json");

                                        Configuration = builder.Build();
                                        }





                                        share|improve this answer













                                        The answers that suggest adding .SetBasePath(env.ContentRootPath) in Startup.cs depend upon a prior step.



                                        First, add the line .UseContentRoot(Directory.GetCurrentDirectory()) to your WebHostBuilder construction in Program.cs like so:



                                        public class Program
                                        {
                                        public static void Main(string args)
                                        {
                                        var config = new ConfigurationBuilder()
                                        .SetBasePath(Directory.GetCurrentDirectory())
                                        .AddEnvironmentVariables()
                                        .Build();

                                        var host = new WebHostBuilder()
                                        .UseConfiguration(config)
                                        .UseKestrel()
                                        .UseContentRoot(Directory.GetCurrentDirectory())
                                        .UseStartup<Startup>()
                                        .Build();

                                        host.Run();
                                        }
                                        }


                                        Then the following will work:



                                        public Startup(IHostingEnvironment env)
                                        {
                                        var builder = new ConfigurationBuilder()
                                        .SetBasePath(env.ContentRootPath)
                                        .AddJsonFile("appsettings.json");

                                        Configuration = builder.Build();
                                        }






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 8 '17 at 19:37









                                        GroppeGroppe

                                        2,07693360




                                        2,07693360























                                            0














                                            If you have done anything with Project Debug Properties, then you may have inadvertently overwritten the starting directory:



                                            Project -> Right-click -> Properties -> Debug -> Profile and then look at the entry in Working Directory.



                                            The simplest is that it be blank.






                                            share|improve this answer




























                                              0














                                              If you have done anything with Project Debug Properties, then you may have inadvertently overwritten the starting directory:



                                              Project -> Right-click -> Properties -> Debug -> Profile and then look at the entry in Working Directory.



                                              The simplest is that it be blank.






                                              share|improve this answer


























                                                0












                                                0








                                                0







                                                If you have done anything with Project Debug Properties, then you may have inadvertently overwritten the starting directory:



                                                Project -> Right-click -> Properties -> Debug -> Profile and then look at the entry in Working Directory.



                                                The simplest is that it be blank.






                                                share|improve this answer













                                                If you have done anything with Project Debug Properties, then you may have inadvertently overwritten the starting directory:



                                                Project -> Right-click -> Properties -> Debug -> Profile and then look at the entry in Working Directory.



                                                The simplest is that it be blank.







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Sep 15 '17 at 16:47









                                                Chris F CarrollChris F Carroll

                                                4,55013343




                                                4,55013343























                                                    0














                                                    You Need to istall Configuration.Json package from Microsoft.Extensions
                                                    or just add Microsoft.Extensions.Configuration.Json to y






                                                    share|improve this answer






























                                                      0














                                                      You Need to istall Configuration.Json package from Microsoft.Extensions
                                                      or just add Microsoft.Extensions.Configuration.Json to y






                                                      share|improve this answer




























                                                        0












                                                        0








                                                        0







                                                        You Need to istall Configuration.Json package from Microsoft.Extensions
                                                        or just add Microsoft.Extensions.Configuration.Json to y






                                                        share|improve this answer















                                                        You Need to istall Configuration.Json package from Microsoft.Extensions
                                                        or just add Microsoft.Extensions.Configuration.Json to y







                                                        share|improve this answer














                                                        share|improve this answer



                                                        share|improve this answer








                                                        answered Oct 25 '18 at 19:06


























                                                        community wiki





                                                        SD Lutonda II Sebastio Dias Lu































                                                            draft saved

                                                            draft discarded




















































                                                            Thanks for contributing an answer to Stack Overflow!


                                                            • Please be sure to answer the question. Provide details and share your research!

                                                            But avoid



                                                            • Asking for help, clarification, or responding to other answers.

                                                            • Making statements based on opinion; back them up with references or personal experience.


                                                            To learn more, see our tips on writing great answers.




                                                            draft saved


                                                            draft discarded














                                                            StackExchange.ready(
                                                            function () {
                                                            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f38282652%2fasp-net-core-1-0-configurationbuilder-addjsonfileappsettings-json-not-fin%23new-answer', 'question_page');
                                                            }
                                                            );

                                                            Post as a guest















                                                            Required, but never shown





















































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown

































                                                            Required, but never shown














                                                            Required, but never shown












                                                            Required, but never shown







                                                            Required, but never shown







                                                            Popular posts from this blog

                                                            Monofisismo

                                                            Angular Downloading a file using contenturl with Basic Authentication

                                                            Olmecas