Sin*_*tic 18 .net-core visual-studio-2017 asp.net-core-2.0
如果我启动一个新的web api项目,appsettings文件将组合在一起.但是,我正在从控制台应用程序模板创建一个工作项目,当我手动创建appsettings文件时,不要组合在一起.我想回到旧版本,我在csproj文件中放了一些东西,但我不知道如何在.net核心中执行此操作,我在属性或配置中没有看到任何内容
Gen*_*Mac 30
在解决方案的项目文件中,您可以编辑或添加<ItemGroup>元素中的<Project>元素.这对我有用:
<ItemGroup>
<Content Include="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="appsettings.Development.json;appsettings.Local.json;appsettings.Production.json;">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
请注意我的控制台项目目标是.Net Core 2.0,并且在Visual Studio Pro 2017版本15.7.5中运行.此外,如果您的解决方案资源管理器没有立即刷新,请尝试卸载并重新加载项目.
按照建议使用<ItemGroup>with给了我一个关于“包含重复的‘内容’项”的错误(在 Visual Studio 2019 中)。事实证明,.NET SDK 默认包含项目目录中的“内容”项。将属性设置为似乎有点僵化,所以现在我将项目包含为.<Content>EnableDefaultContentItemsfalse<None>
<ItemGroup>
<!-- Group AppSettings in Console project. Use None to prevent "Duplicate 'Content' items were included" when using (default) EnableDefaultContentItems=true -->
<None Include="appsettings.*.json">
<DependentUpon>appsettings.json</DependentUpon>
</None>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
这确实显示了分组的文件,但在解决方案资源管理器中显示了其构建操作“无”和“不复制”的属性,所以我想这就是希望它们分组的代价?
FWIW: appsettings-json-not-in-hierarchy中建议的文件嵌套规则 不会将文件显示为分组/嵌套,但如果按下解决方案资源管理器折叠按钮,则会使其折叠。
| 归档时间: |
|
| 查看次数: |
2419 次 |
| 最近记录: |