如何让控制台项目对我的 appsettings.json 文件进行分组? [英] How do I get a console project to group my appsettings.json files?

查看:25
本文介绍了如何让控制台项目对我的 appsettings.json 文件进行分组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我开始一个新的 web api 项目,appsettings 文件会组合在一起.但是,我正在从控制台应用程序模板创建一个工作项目,并且当我手动创建 appsettings 文件时,它们不会组合在一起.我回想在旧版本中,我会在 csproj 文件中添加一些内容,但我不知道如何在 .net 核心中执行此操作,并且在属性或配置中看不到任何内容

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

推荐答案

在解决方案的项目文件中,您可以在 中编辑或添加 <ItemGroup> 元素; 元素.这对我有用:

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>

请注意,我的控制台项目针对 .Net Core 2.0 并且是在 Visual Studio Pro 2017 版本 15.7.5 中运行.此外,如果您的解决方案资源管理器没有立即刷新,请尝试卸载并重新加载项目.

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.

这篇关于如何让控制台项目对我的 appsettings.json 文件进行分组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆