尝试删除 NLog.config 结果 "Cannot modify an evaluated object originating in an imported file"

Trying to remove NLog.config results in "Cannot modify an evaluated object originating in an imported file"

我一直在将NLog.config的内容移到我的App.config中,正准备删除原来的nlog配置文件。

但是 Visual Studio 2017 Enterprise (15.8.4) 阻止我这样做并显示以下错误消息:

Cannot modify an evaluated object originating in an imported file. C:......csproj.nuget.g.props

打开上述文件时,我发现以下部分:

  <ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<None Include="$(NuGetPackageRoot)nlog.config.5.10\contentFiles\any\any\NLog.config" Condition="Exists('$(NuGetPackageRoot)nlog.config.5.10\contentFiles\any\any\NLog.config')">
  <NuGetPackageId>NLog.Config</NuGetPackageId>
  <NuGetPackageVersion>4.5.10</NuGetPackageVersion>
  <NuGetItemType>None</NuGetItemType>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
  <TargetPath>NLog.config</TargetPath>
  <Private>True</Private>
  <Link>NLog.config</Link>
</None>

删除 <ItemGroup> 部分后,NLog.config 消失了,但又出现了自动生成的默认内容。

长话短说:当我将所有配置内容移动到 App.config

后,如何删除项目根目录下的文件 NLog.config

看起来像 NuGet 的东西。您可能必须删除软件包并找到一个不设置配置文件而只安装 DLL 的软件包。

根据@matze

删除用 NLog 替换包 NLog.Config 成功了