Visual Studio 2017 v15.3 没有复制 nlog.config

Visual Studio 2017 v15.3 doesn't copy nlog.config

我刚刚更新到 Visual Studio 2017 v15.3Core 2.0 SDK

我正在与 Igans Sakalauskas 合作 Net Core Knockout project,它是在 VS 2017 中使用 Core 1.1 构建的。

https://ignas.me/tech/net-core-knockoutjs-web-application/

我已将 EnableDefaultContentItems 保留为默认值 true,并从 WebApplication1.Web 项目的 .csproj 文件中删除了 Content Include 语句。

他正在使用nlog并且项目的根目录中有一个nlog.config。项目构建成功,但在 运行 时抛出 file not found error。它正在 WebApplication1.Web\bin\Debug\netcoreapp1.1 文件夹中寻找 nlog.config。如果我手动复制项目运行的文件并且所有测试都通过。

我无法开始工作的是 VS 在项目构建时复制 nlog.config

如果我添加

  <ItemGroup>
    <Content Include="nlog.*" />
  </ItemGroup>

.csproj 我得到 Duplicate 'Content' items ... The duplicate items were: 'nlog.config' 错误。 https://aka.ms/sdkimplicititems

如果我注释掉 Contnet Include 并将 EnableDefaultContentItems 设置为 false

<PropertyGroup>
    <EnableDefaultCompileItems>false</EnableDefaultCompileItems>
</PropertyGroup>

我得到一个 Suppression State Error CS5001 Program does not contain a static 'Main' method suitable for an entry point

如果我随后恢复“Content Inculde”语句,则会出现此错误:

Duplicate 'Content' items ... The duplicate items were: 'list of files'错误

Default Content Items 正在处理 wwwroot 子文件夹中的 .js.cs 文件。

如果 VS 在我 Content Include 一个项目时抛出 Duplicate Content 错误,为什么它不复制没有 Content Include 的文件?

在 VS 2017 15.3 中,如何配置将文件 nlog.config 从项目的根目录复制到 bin 子目录?

这与重复的内容项无关。

恢复到 Visual Studio 2017 年的 recommended approach to handling duplicate content errors;这是你开始的:

I've left EnableDefaultContentItems to the default of true and removed the Content Include statements from the .csproj file in the WebApplication1.Web project.

现在将其添加到您的 .csproj 文件中:

<ItemGroup>
  <Content Update="nlog.config">
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </Content>
</ItemGroup>

这告诉 Visual Studio 更新现有的内容规则(自动生成的规则),使其在生成时将文件复制到输出目录中。