【问题标题】:How to unlock NLog.config on Visual Studio 2019如何在 Visual Studio 2019 上解锁 NLog.config
【发布时间】:2021-05-11 09:29:42
【问题描述】:

使用 NuGet 包管理器安装 NLog 和 NLog.config 后 我无法编辑 NLog.config,它会显示锁定图标。 如何解锁?

【问题讨论】:

    标签: .net visual-studio visual-studio-2019 nlog nlog.config


    【解决方案1】:

    对于较新的项目,NLog.Config 包不是 推荐。

    发件人:https://www.nuget.org/packages/NLog.config

    注意:不幸的是,这个包在使用时不能很好地工作 <PackageReference>

    建议:

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题 - Nlog 配置的 NuGet 包安装在与项目根目录不同的位置,例如 C:\Users\User\.nuget\packages\nlog.config\4.7.7\contentFiles\any\any\NLog.config 而不是 I:\workspaceVS\net50\ConsoleCoreApp1

      我设法通过手动将文件 Nlog.config 复制到项目的根目录中来解决问题,然后通过以下方式在我的 .csproj 文件中引用它:

      <Project Sdk="Microsoft.NET.Sdk">
        ...
        <ItemGroup>    
          <None Update="NLog.config">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          </None>
          <None Update="NLog.xsd">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
          </None>
          ...
        <ItemGroup>
      </Project>
      

      而不是:

      <Project Sdk="Microsoft.NET.Sdk">
        ...
        <ItemGroup>    
          <None Update="C:\Users\User\.nuget\packages\nlog.config\4.7.7\contentFiles\any\any\NLog.config">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          </None>
          <None Update="C:\Users\User\.nuget\packages\nlog.schema\4.7.7\contentFiles\any\any\NLog.xsd">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
          </None>
          ...
        <ItemGroup>
      </Project>
      

      现在,当我释放它时,它直接显示在输出目录中:

      .(I:\workspaceVS\net50\ConsoleCoreApp1\bin\Release\net5.0\win-x86)
      ├── ...                   
      └── Nlog.config           # Holds the configuration for Nlog
      

      【讨论】:

        【解决方案3】:

        您可以在{Project Folder}\bin\Debug\net5.0\ 中找到NLog.config 文件。您可以使用记事本或 Visual Studio 随意打开和编辑它。

        【讨论】:

          猜你喜欢
          • 2020-04-04
          • 1970-01-01
          • 2020-02-14
          • 2020-12-26
          • 2021-12-24
          • 1970-01-01
          • 1970-01-01
          • 2020-10-31
          • 2020-04-02
          相关资源
          最近更新 更多