【问题标题】:How do you copy folders from dotnet core project to publish folder. Specifically .cshtml files如何将文件夹从 dotnet core 项目复制到发布文件夹。特别是 .cshtml 文件
【发布时间】:2021-02-09 20:06:28
【问题描述】:

当使用诸如

之类的例子时
<!--Include in publish-->
  <ItemGroup>
    <None Include="exampleDirectory\**\*.*" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
  </ItemGroup>

此文件夹包含 .cshtml.cshtml.cs 文件,但仅复制 .cshtml.cs 文件。这些文件没有复制过来是否有特定原因?

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

我将其设置为 &lt;None,因为我需要有两个目录,而使用 &lt;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]

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

【问题讨论】:

  • @JeremyLakeman 我不这么认为。我正在寻找这些文件夹的直接副本。这样做,代码库可以呈现这些根本不连接到 RazorPages 的视图。他们用System.IO.File.ReadAllTextAsync(读入

标签: c# .net-core


【解决方案1】:

为什么你有'None'

示例: &lt;ItemGroup&gt; &lt;Content Include="AppData\**" CopyToPublishDirectory="PreserveNewest"/&gt; &lt;/ItemGroup&gt;

【讨论】:

  • 更新了我的问题。这也是我见过的一个示例,但使用该示例仍然会导致仅复制 .cshtml.cs 文件。不是.cshtml 文件。
  • 对于初学者,请尝试仅定位“~/*.cshtml”而不是“~/*.cshtml.*”,您在使用“.”时会定位所有内容
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-31
  • 1970-01-01
  • 2016-10-23
  • 2014-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多