How to unlock NLog.config on Visual Studio 2019

Viewed 3096

After installing NLog and NLog.config using NuGet package manager I am unable to edit NLog.config, it shows lock icon on it. How to unlock it?

lock icon on NLog.config file

my solution explorer

3 Answers

I had the same problem - the NuGet package for Nlog config was installed in a different location than the root project directory, like for example C:\Users\User\.nuget\packages\nlog.config\4.7.7\contentFiles\any\any\NLog.config instead of I:\workspaceVS\net50\ConsoleCoreApp1.

I managed to solved the problem by copying manually the file Nlog.config into the project's root directory and then reference it in my .csproj file in the following way :

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

instead of :

<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>

And now, when I release it, it shows directly in the output directory :

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

You can find the NLog.config file in {Project Folder}\bin\Debug\net5.0\. You can open and edit it as you like with Notepad or Visual Studio.

Related