25

I'm using Octopack / Nuspec file to build my nuget package.

I would like to exclude certain folders which exist in the project. e.g. the "obj" file. I've been trying to get the exclude tag to work, but haven't had any luck. The nuget file builds, but the folder is still there.

Sadly, all the examples on the net specific file types and not folder.

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>Foo</id>
    <title>Foo</title>
    <version>$version$</version>
    <authors>NA</authors>
    <owners>NA</owners>
    <licenseUrl>http://Foo</licenseUrl>
    <projectUrl>http://Foo</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Foo</description>
    <releaseNotes>NA</releaseNotes>
  </metadata>
  <files>
    <file src="obj\**\*.*" exclude="*.*" />
  </files>
</package>
rbrayb
  • 46,440
  • 34
  • 114
  • 174
Kye
  • 5,919
  • 10
  • 49
  • 84

3 Answers3

39

I needed to create a WebApplication, but deploy it as a standard ASP.NET website using "CodeFile" attributes.

This was basically to update a page in the standard ADFS login site.

<files>
  <file src="**" exclude="**\*.dll;**\*.designer.cs;**\*.csproj;**\*.pdb;**\*.user;**\*.vspscc;bin\*.cs;bin\*.aspx;bin\*.config;bin\*.asax;bin\*.pubxml" />
</files>
knocte
  • 16,941
  • 11
  • 79
  • 125
Kye
  • 5,919
  • 10
  • 49
  • 84
  • 1
    Are you required to use NuGet for this? I wonder if a [Web Deploy package](http://www.iis.net/learn/publish/using-web-deploy/building-a-web-deploy-package-from-visual-studio-2010) might be a little better fit for what you're trying to accomplish. – John Hoerr Jan 23 '13 at 01:06
  • 1
    Yeah. We needed to use octopus deploy so nuget was a requirement. – Kye Jan 23 '13 at 10:42
  • I was tried to use this solution. but unfortunately, nothing has happened? – Baskar John Aug 17 '21 at 12:54
11

To directly answer the posters question, if you want to exclude only the obj folder from a Nuget package use the following in your nuspec xml

<files>
    <file src="*\**" target="\" exclude="obj\**\*.*"/>
</files>
KShan
  • 611
  • 7
  • 12
1

Depending on the project you are building, you shouldn't need to exclude anything.

If you are building a Windows Service/Console application, OctoPack should only package your bin\release directory.

If you are building a web application, you should use a 'publish' command to have MSBuild sent the binaries and content files to a temporary folder, and OctoPack will package that. This way your obj folders and C# files won't be packaged.

For information on how to do this, please see the section on Web Application Publishing at:

http://octopusdeploy.com/documentation/packaging/octopack

Paul Stovell
  • 32,377
  • 16
  • 80
  • 108
  • can you update this answer? I don't see a "Web Application Publishing" section on the linked page. My specific issue is that the bin\Roslyn folder is being included in the nupkg. I tried using a publishing profile and running msbuild against the csproj instead, but that did not work: &$msbuildExe ..\trunk\WebUI\WebUI.csproj /p:DeployOnBuild=true /p:PublishProfile=local /p:RunOctoPack=true – b_levitt Jun 08 '16 at 13:58
  • It's include files like EntityFramework.dll, which are dependencies on separate NuGet packages, NOT files that should be inlcuded in my nupkg file. How does one exclude them? – Triynko Aug 28 '17 at 23:00
  • The question wasn't for advise. It was explicitly for excluding a folder from a nuget package. – Dean Martin Oct 18 '18 at 12:31