【问题标题】:dotnetcore CopyToOutputDirectory creates deep nested folder structuredotnetcore CopyToOutputDirectory 创建深层嵌套文件夹结构
【发布时间】:2023-05-17 08:32:01
【问题描述】:

有以下配置

<Content Include="**/*.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>

创建一个深度嵌套的结构,例如 bin > debug > netstandard2.0 > [带有 json 文件的文件夹] 然后再次 bin > debug > netstandard2.0 > [带有 json 文件的文件夹] bin > ...

即使项目只有扁平结构 根

[文件夹] *json 文件

所以预计只有 bin > 调试 > netstandard2.0 > 文件夹

这是在 macos 上使用 jetbrains Rider,在构建时也会发生 点网构建

谢谢。

【问题讨论】:

  • 它似乎在后续构建中这样做,例如第一个构建创建一个正确的一级副本,在下一个构建中,它在输出目录 bin > debug > netstandard2.0 > bin > debug > netstandard.. 中添加另一个级别,并继续递归地这样做。

标签: .net-core csproj


【解决方案1】:

根据其 Web 项目还是非 Web 项目(使用 SDK),您应该更新已设置必要排除项的现有项目:

<None Update="**/*.json" CopyToOutputDirectory="PreserveNewest" />
<!-- Web SDK sets some JSON files to Content -->
<Content Update="**/*.json" CopyToOutputDirectory="PreserveNewest" />

或者,如果您想向内容项添加一些文件,请使用以下排除项:

<Content Include="**\*.txt"
         CopyToOutputDirectory="PreserveNewest"
         Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder);$(DefaultWebContentItemExcludes)" />
<!-- ensure that project systems aren't confused when the same file is listed in different items -->
<None Remove="**\*.txt" />

【讨论】: