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;
}
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
add a comment |
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
add a comment |
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
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
asp.net asp.net-core asp.net-core-2.0
edited Mar 6 '18 at 12:40
Ajay2707
4,42142345
4,42142345
asked Jul 9 '16 at 14:06
ZhorianZhorian
4971513
4971513
add a comment |
add a comment |
10 Answers
10
active
oldest
votes
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.
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
add a comment |
You need to add the package below:
"Microsoft.Extensions.Configuration.Json": "1.0.0"
This was what i was missing. Thanks!
– Tadej
Dec 6 '17 at 7:35
add a comment |
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)
});
Thank you!builder.SetBasePath(Directory.GetCurrentDirectory());
fixed it for me.
– w0ns88
Dec 11 '18 at 9:18
add a comment |
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 ....
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
add a comment |
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;
add a comment |
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>
Thank you a lot!
– Vitaliy
Jun 12 '18 at 12:50
add a comment |
Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"
add a comment |
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();
}
add a comment |
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.
add a comment |
You Need to istall Configuration.Json package from Microsoft.Extensions
or just add Microsoft.Extensions.Configuration.Json to y
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
You need to add the package below:
"Microsoft.Extensions.Configuration.Json": "1.0.0"
This was what i was missing. Thanks!
– Tadej
Dec 6 '17 at 7:35
add a comment |
You need to add the package below:
"Microsoft.Extensions.Configuration.Json": "1.0.0"
This was what i was missing. Thanks!
– Tadej
Dec 6 '17 at 7:35
add a comment |
You need to add the package below:
"Microsoft.Extensions.Configuration.Json": "1.0.0"
You need to add the package below:
"Microsoft.Extensions.Configuration.Json": "1.0.0"
answered Jul 29 '16 at 20:51
user6655970user6655970
20114
20114
This was what i was missing. Thanks!
– Tadej
Dec 6 '17 at 7:35
add a comment |
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
add a comment |
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)
});
Thank you!builder.SetBasePath(Directory.GetCurrentDirectory());
fixed it for me.
– w0ns88
Dec 11 '18 at 9:18
add a comment |
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)
});
Thank you!builder.SetBasePath(Directory.GetCurrentDirectory());
fixed it for me.
– w0ns88
Dec 11 '18 at 9:18
add a comment |
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)
});
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)
});
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
add a comment |
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
add a comment |
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 ....
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
add a comment |
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 ....
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
add a comment |
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 ....
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 ....
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
add a comment |
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
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
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
add a comment |
add a comment |
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>
Thank you a lot!
– Vitaliy
Jun 12 '18 at 12:50
add a comment |
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>
Thank you a lot!
– Vitaliy
Jun 12 '18 at 12:50
add a comment |
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>
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>
answered Mar 25 '18 at 23:13
SchattenJagerSchattenJager
228111
228111
Thank you a lot!
– Vitaliy
Jun 12 '18 at 12:50
add a comment |
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
add a comment |
Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"
add a comment |
Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"
add a comment |
Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"
Right click appsettings.json -> Properties, then makes sure that Copy to Output Directory is set to "Copy Always"
answered Jan 4 at 18:36
user3413723user3413723
4,3333440
4,3333440
add a comment |
add a comment |
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();
}
add a comment |
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();
}
add a comment |
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();
}
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();
}
answered Nov 8 '17 at 19:37
GroppeGroppe
2,07693360
2,07693360
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Sep 15 '17 at 16:47
Chris F CarrollChris F Carroll
4,55013343
4,55013343
add a comment |
add a comment |
You Need to istall Configuration.Json package from Microsoft.Extensions
or just add Microsoft.Extensions.Configuration.Json to y
add a comment |
You Need to istall Configuration.Json package from Microsoft.Extensions
or just add Microsoft.Extensions.Configuration.Json to y
add a comment |
You Need to istall Configuration.Json package from Microsoft.Extensions
or just add Microsoft.Extensions.Configuration.Json to y
You Need to istall Configuration.Json package from Microsoft.Extensions
or just add Microsoft.Extensions.Configuration.Json to y
answered Oct 25 '18 at 19:06
community wiki
SD Lutonda II Sebastio Dias Lu
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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