Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a console project to group my appsettings.json files?

If I start a new web api project, the appsettings files are grouped together. However, I'm creating a working project from the console app template and when I create the appsettings files manually, the do not group together. I think back in older versions, there was something I'd put in the csproj file, but I don't know how to do it in .net core and I'm not seeing anything in properties or configurations

enter image description here

like image 284
Sinaesthetic Avatar asked Jul 09 '18 20:07

Sinaesthetic


People also ask

How do I add Appsettings json to project?

Add Json File After adding the file, right click on appsettings. json and select properties. Then set “Copy to Ouptut Directory” option to Copy Always. Add few settings to json file, so that you can verify that those settings are loaded.

Can we have multiple Appsettings json?

Of course, we can add and use multiple appsettings. json files in ASP.NET Core project. To configure and read data from your custom json files, you can refer to the following code snippet.

Can I move Appsettings json out of the app directory?

Yes, I'm leaving appsettings. json in the project and it's being deployed - for documentation and non-sensitive settings. And, yes, I could leave sensitive data encrypted in Visual Studio Online but for now, the simplest thing to do is hide an overriding version elsewhere in the file system, as I'm doing.


1 Answers

In the project file of your solution you can edit or add an <ItemGroup> element within the <Project> element. This worked for me:

  <ItemGroup>     <Content Include="appsettings.json">       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>     </Content>     <Content Include="appsettings.*.json">       <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>       <DependentUpon>appsettings.json</DependentUpon>     </Content>   </ItemGroup> 

Please Note that my console project targets .Net Core 2.0 and is running in Visual Studio Pro 2017 Version 15.7.5. Also, if your Solution Explorer doesn't immediately refresh try unloading and reloading the project.

like image 80
General Mac Avatar answered Oct 04 '22 23:10

General Mac