4
votes

I'm using nuget pack myproject.csproj to package up a DLL, but I would like to include a config template also. Here's the related nuspec file:

<?xml version="1.0"?>
<package >
    <metadata>
        <id>$id$</id>
        <version>$version$</version>
        <title>$title$</title>
        <authors>Chris Vann</authors>
        <owners>MyCompany</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Log4net appenders for targeting MS Azure</description>
        <releaseNotes></releaseNotes>
        <copyright>Copyright 2014</copyright>
        <tags>log4net logging azure</tags>
    </metadata>
    <files>
        <file src="log4net.config" target="."/>
    </files>
</package>

Nuget correctly imports the metadata but seems to ignore the files element completely when packing the csproj file. Is there a work around for this?

2

2 Answers

4
votes

After some fine debugging of the NuGet.exe command line tool here's my answer:

NuGet.exe uses default excludes list to exclude some usually unwanted files from your package. This list also contains any file/folder starts with a dot.

Setting the target of a file in your nuspec to "." excludes it from the package when you use the pack command.

The solution is one of the following: (a) Omit the target attribute (equivalent to setting the target to "") (b) Use -NoDefaultExcludes option, example: pack myproj.csproj -NoDefaultExcludes

Both solutions will result the same as you intended - a file named log4net.config will be placed the the top folder of the package, next to the .nuspec file and lib folder. I personally suggest you use option (a), since "." folder has no meaning other than the root folder.

A little note: it seems to me that you need to add log4net.config to the lib folder, next to the DLL, rather than to the package's root folder.

-2
votes

When you nuget pack a project file it doesn't look at the nuspec file. It is very basic. If you want more control like specifying files, you will need to use nuget pack mypackage.nuspec

Note: once you include a files section, you have to list all files.