1
votes

I am setting up a NuGet package for my team to use for all of our projects, internally. It contains code for configuring the NLog logger for whichever project references the package. However, our custom NLog.config file is not showing up in the final build, but all of the other files included in the NuGet package are there.

Here's my nuspec file:

<?xml version="1.0"?>
    <package >
      <metadata>
        ...
      </metadata>
      <files>
        <file src="bin\Release\*.*" target="lib\net45" />    
      </files>
    </package>

I tried adding this to the files, but it was redundant, and changed nothing:

<file src="bin\Release\NLog.config" target="lib\net45" />

Since we're including all of the files with *.*, they all show up in the .nupkg file in the lib/net45 folder. All of the .dlls, .xmls, and .configs are in the nupkg, including the NLog.config. So the file I need is making it into the package just fine.

The problem happens when I include this NuGet package in a project and look at the build output. The application's build output contains everything in the nupkg that I need, except the NLog.config. Even the Utilities.dll.config is included.

Is there something that needs to be specified in the nuspec file? Or in the Visual Studio project such as MSBuild settings? How do I make sure all of the files included in the NuGet package are copied to the application's build output?

2

2 Answers

0
votes

Do you check nlog.config file properties?

If file properties - which is "Copy to Output Directory" is "Do Not Copy", hence you cannot see config fil into Release folder.

Besides, if you want to download NLog.config file into main directory, target must be emtpy.

In my case, I have used below line in my nuspec file: <file src="bin\Release\content\log4net.config" target=""></file>

Properties

1
votes

I was able to fix this with Adam Catamak's suggestion, and looking through the nupkg for NLog's own config package to see how they did it.

The nuspec file that worked for me looked like this:

<?xml version="1.0"?>
<package >
  <metadata>
    ...
  </metadata>
  <files>
    <file src="bin\Release\*.*" target="lib\net45" />
    <file src="bin\Release\NLog.config" target="content"/>
    <file src="Install.ps1" target="tools"/>
  </files>
</package>

If you don't use Install.ps1, the user will have to manually update it to "Copy Always" every time the package is updated. Here is the Install.ps1 that NLog uses:

param($installPath, $toolsPath, $package, $project)

$configItem = $project.ProjectItems.Item("NLog.config")

# set 'Copy To Output Directory' to 'Copy if newer'
$copyToOutput = $configItem.Properties.Item("CopyToOutputDirectory")
$copyToOutput.Value = 1

# set 'Build Action' to 'Content'
$buildAction = $configItem.Properties.Item("BuildAction")
$buildAction.Value = 2