How to get rid of lib and content folder in nuget package?

TeamCity Professional 9.1.7 (build 37573)
Octopus 3.3.17
Nuget.exe 3.4.3 (default in Teamcity)

We are using Nuget.exe(instead of Octopack) to pack our output build artifacts to be published onto TC nuget feed and then consumed by Octopus for deployments. We don’t need the lib and content folders as explained on Octopus documentation:

Tip: Structure the package as you want it extracted on disk. NuGet was designed for packaging libraries to be used in Visual Studio, which is a different usage scenario than that of deploying applications. When creating a library NuGet package, for example, NuGet encourages you to put binaries in a lib folder, and content files in the content folder. But for Octopus Deploy, this convention doesn’t make sense - your ASP.NET application will expect binaries to be in a bin folder for example. Instead, just ignore the NuGet package structure conventions, and simply structure your package exactly like you want it to appear when extracted on disk.

We are using Teamcity’s ‘Nuget Pack’ runner and passing the .csproj files to the pack command. We also have a custom nuspec file to pack artifacts into bin folder and the web.config to the root of the nuget package (to reiterate, we invoke nuget pack on .csproj instead of .nuspec)

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
  <metadata>
    <version>$version$</version>
    <authors>Removed</authors>
    <owners>Removed</owners>
    <id>Removed</id>
    <title>Removed</title>
    <requireLicenseAcceptance>Removed</requireLicenseAcceptance>
    <description>Removed</description>
    <copyright>Removed</copyright>
    <dependencies>
      <dependency id="AutoMapper" version="4.2.1" />
      <dependency id="CommonServiceLocator" version="1.3" />
    </dependencies>
  </metadata>
  <files>
    <file src="bin\*.dll" target="bin\" />
    <file src="bin\*.pdb" target="bin\" />
    <file src="Enterprise\Schemas\*.*" target="Enterprise\Schemas\" />
    <file src="Web.config" target="Web.config" />
   <file src="Web.DevTest.config" target="Web.DevTest.config" />
    <file src="Web.SysTest.config" target="Web.SysTest.config" />
    <file src="Web.PreProd.config" target="Web.PreProd.config" />
    <file src="Web.Prod.config" target="Web.Prod.config" />
  </files>
</package>

Now, the output nuget package contains bin folder and the .config files in the root as expected, but it also contains bin and lib folders.

I can’t seem to find an option to get this of these folders in the output package. These folders are redundant for us and make no difference to the final deployment, but we don’t need them there. We can of course delete them using a script pot-deployment, but surely there would be an option to exclude them at the nuget pack stage itself.

Small typo:
Now, the output nuget package contains bin folder and the .config files in the root as expected, but it also contains lib and content folders.

Just to add, this is the reason why we invoke nuget pack on .csproj file instead of .nuspec file:

*$version$ gets replaced by the version specified in the AssemblyVersionAttribute (or AssemblyInformationalVersionAttribute if present) applied to your assembly (typically within the AssemblyInfo.cs file).

These tokens will only be replaced when you execute the pack command with the project file, and not with the nuspec file. The contents of the nuspec file will be located and honored, with the appropriate token replacements executed.*

Just wanted to check with Octopus Support, if anyone has had a chance to look into this?

Hi Chetan,

Thanks for reaching out! So sorry about the delay in responding to your question. I’d love to figure out why it’s adding those folders to your NuGet package automatically. Would you mind sending me your TeamCity build log that shows this happening? That will hopefully get us going to figure out why it’s doing that.

Kind regards,

Kenny

Notice:

This issue has been closed due to inactivity. If you encounter the same or a similar issue and require help, please open a new discussion (if we asked for logs or extra details in this thread, consider including them in the new thread). If you are the creator of this thread and believe it should not be closed let us know via our support email.