jenkinsnugetjenkins-pipelinenuget-packageoctopack

How to exclude directory and files from NuGet package built with Octopack via Jenkins?


I have a windows service that I need to pack into a nuget package with OctoPack, but I have to exclude a directory called "Config" and a few other config files (these are instance specific and this will be deployed to multiple instances.) However the files are always included no matter what I put in the nuspec file.

Project directory:

Config <dir>
Code <dir>
app.config
settings.config
service.csproj
service.nuspec

Nuspec file:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <!-- Required elements-->
        <id>service</id>
        <version>0.0.0</version>
        <description>service for app</description>
        <authors>our team</authors>
    </metadata>
    <!-- Optional 'files' node -->
    <files>
        <file src="**" exclude="Config\" />
        <file src="**" exclude="**\app.config" />
        <file src="**" exclude="**\settings.config" />
    </files>
</package>

Jenkins file:

bat "dotnet-octo pack --id=service --format=NuPkg --basePath=bin\\x64\\BuildServer --version=0.0.0.${env.BUILD_ID} --overwrite"

I'm sure there is an error in my nuspec file or something but I can't find any documentation for my specific case. Thanks.


Solution

  • Turns out I was way overthinking this. I just edited the Jenkins file to delete them before packing. Completely forgot that bat was an option.

    bat "del bin\\x64\\BuildServer\\app.config"
    bat "del bin\\x64\\BuildServer\\settings.config"
    bat "rmdir /s /q bin\\x64\\BuildServer\\Config"
    bat "dotnet-octo pack --id=service --format=NuPkg --basePath=bin\\x64\\BuildServer --version=0.0.0.${env.BUILD_ID} --overwrite"
    

    However, the correct way to do it via nuspec would have been

    <files>
        <file src="bin\x64\BuildServer\**\*.*" exclude="bin\x64\BuildServer\app.config;bin\x64\BuildServer\settings.config;bin\x64\BuildServer\Config\*.xml" />
    </files>
    

    src means "include all directories and files in bin\x64\BuildServer, where all the dlls and such are after building. And exclude means except these files. Note all paths are relative to where your nuspec file is (this is important!!!).