【发布时间】:2021-12-23 01:19:36
【问题描述】:
我正在尝试“嵌套”我的 appsettings.[environment].json 文件,如下所示:
为此,我在 csproj 中执行以下操作:
<ItemGroup>
<Content Include="appsettings.Development.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
<Content Include="appsettings.Staging.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
<Content Include="appsettings.Production.json">
<DependentUpon>appsettings.json</DependentUpon>
</Content>
</ItemGroup>
现在我已经这样做了,我收到以下 csproj 警告:
严重性代码描述项目文件行抑制状态 错误 NETSDK1022 包含重复的“内容”项目。默认情况下,.NET SDK 包含项目目录中的“内容”项。您可以从项目文件中删除这些项目,或者如果您想将它们显式包含在项目文件中,则将“EnableDefaultContentItems”属性设置为“false”。有关详细信息,请参阅https://aka.ms/sdkimplicititems。重复的项目是:'appsettings.Development.json'; 'appsettings.Production.json'; 'appsettings.Staging.json' Homely.Listings.Apis.UrlStateSystem C:\Program Files\dotnet\sdk\6.0.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.Shared.targets 213
现在那里的链接说我可以做到:
<PropertyGroup>
<EnableDefaultItems>false</EnableDefaultItems>
</PropertyGroup>
但这意味着我需要手动包含所有其他文件,所以我又回到了 csproj 糟糕的过去。
那么 -> 这是在较新的 csproj SDK 格式中执行 NESTED 文件的正确方法吗?
【问题讨论】:
标签: .net