2017-09-27 67 views
0

我刚更新到Visual Studio 2017 v15.3Core 2.0 SDKVisual Studio 2017 v15.3不复制nlog.config

我与Igans Sakalauskas' Net Core Knockout project工作,它与Core 1.1建于2017年VS

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

我已经离开EnableDefaultContentItems到的真实的默认和删除Content Include语句从.csproj文件在WebApplication1.Web项目中。

他正在使用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

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

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

如果我再恢复'内容Inculde的陈述就给出了这样的错误:

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

Default Content Items正在wwwroot子文件夹中使用.js.cs文件。

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

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

回答

2

这与重复的内容项无关。在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来更新现有的内容规则(自动生成一个),它复制将该文件放入构建的输出目录中。

+0

你好Daniel。我刚刚发布了我的答案,即在VS'nlog.config'中突出显示,并在Properties中将Copy to Output Directory状态更改为将您的答案写入'.csproj'。但你击败了我,所以你得到了投票。仍然没有回答为什么设置“EnableDefaultContentItems”为false的第二个问题不起作用。你有什么想法吗?请让我知道,所以如果你不知道,我会知道发布一个单独的问题。 – Joe

+0

@Joe最可能的问题是:'EnableDefaultCompileItems'不在正确的位置,没有被应用,或者内容包含问题。通过删除内容包含并删除“EnableDefaultCompileItems”来避免整个问题是最容易的,这对我来说非常有效,我还没有发现需要EnableDefaultCompileItems。 –