首页 > 解决方案 > 如何将文件夹从 dotnet core 项目复制到发布文件夹。特别是 .cshtml 文件

问题描述

使用示例时,例如

<!--Include in publish-->
  <ItemGroup>
    <None Include="exampleDirectory\**\*.*" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
  </ItemGroup>

此文件夹有.cshtml.cshtml.cs文件,但仅.cshtml.cs复制文件。这些文件不复制是否有特定原因?

将所需文件夹复制并粘贴到发布输出目录中即可。这意味着如果这种复制机制刚刚工作并复制了所有文件,这将不是问题。

我之所以设置它,是<None因为我需要有两个目录,并且 using<Content给出了使用两个内容的错误。

C:\Program Files\dotnet\sdk\3.1.404\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.DefaultItems.targets(318,5): error NETSDK1022: Duplicate 'Content' items were included. The .NET SDK includes 'Content' i
tems from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultContentItems' property to 'false' if you want to explicitly include them in yo
ur project file. For more information, see https://aka.ms/sdkimplicititems. The duplicate items were: 'dirName\fileName.cshtml'; 'dirName\fileName.cshtml' [C:\path\to\projectName.csproj]

当设置为 false 时,EnableDefaultContentItems它​​仍然不会复制.cshtml文件,只是复制.cshtml.cs文件。

标签: c#.net-core

解决方案


为什么你有“无”

例子: <ItemGroup> <Content Include="AppData\**" CopyToPublishDirectory="PreserveNewest"/> </ItemGroup>


推荐阅读