28

So I'm actually trying to package up a web site project (not web application so no csproj file) into a NuGet package ready for Octopus to consume but am running into one brick wall after another..

I looked into using OctoPack but it doesn't support web site projects only web application projects.

I am now trying to find a way of adding a folder (in my case a web site) into a Nuget package but Nuget doesn't allow this via the command line does it? It also requires a .csproj file!

I've also tried trying to create the NuGet spec files and pass it in a folder but not possible?

For the moment I may have to use the NuGet package explorer but I want to script this.

I've looked at this question but doesn't seem to handle my scenario Can I create a nuget package without a project file

So does anyone know how to best add a folder to a NuGet package via the command line!?

Community
  • 1
  • 1
Lee Englestone
  • 4,545
  • 13
  • 51
  • 85

1 Answers1

46

I don't know OctoPack, but with nuget.exe, packaging is done in two steps:

  1. Either create a .nuspec manually, or generate one from a .csproj or existing assembly (see nuget spec in the docs).
  2. Call nuget pack with the .nuspec created in the previous step as a parameter.

Since you don't have a .csproj lying around, you're stuck creating the .nuspec manually (or with a GUI tool like NuGet Package Explorer).

You can read all about how to create a .nuspec file in the Nuspec Reference, specifically the section about Specifying Files to Include in the Package.

If you want to include a folder (recursively?) in the package, you need to add something like this to the XML:

<files>
  <file src="bin\Release\**\*.*" target="content" /> 
</files>

This will take all the files and (recursive) sub-folders of the bin\Release folder and put them in the content folder of the NuGet package.

I have no idea what format OctopusDeploy expects in the packages, but that's how you include a folder in the package.

EDIT: There seems to be some documentation on this in the OctoPack README.

Wiebe Tijsma
  • 10,173
  • 5
  • 52
  • 68
khellang
  • 17,550
  • 6
  • 64
  • 84
  • This recursive syntax may be what i'm looking for, i'll try that next. Thanks. – Lee Englestone Jul 03 '14 at 10:49
  • Now if I can find a way of getting around / rid of the compulsory? / content folder that is created when extracting the nuget package i'll be happy – Lee Englestone Jul 03 '14 at 13:44
  • 3
    If you don't specify a target (`content`), it'll put everything in the root. Content is a [special folder](http://docs.nuget.org/docs/reference/nuspec-reference#Content_Files) in NuGet packages. – khellang Jul 03 '14 at 14:02
  • 1
    @LeeEnglestone I am also stuck at the point. Were you able to create octopus compatible nuget package from web site project? Please share the steps you followed. – Wasim Shaikh Feb 13 '15 at 14:06
  • @khellang: I cant see how 'Content' is a special folder. As far as I understand, 'Content' is just the folder name under which the current sourcefiles will be placed under. It could just aswell be another folder name, right? – Emil G Apr 24 '15 at 08:52
  • @EmilG Content is special in that VS will unpack it's contents and add it to the project you're installing the package into, as source files. See [the docs](http://docs.nuget.org/create/nuspec-reference#content-files). WRT OctopusDeploy, it might be just a regular folder, though :) – khellang Apr 24 '15 at 09:05
  • @EmilG: as khellang said, content is only special for VS. Octopus will unpack the package at the installation directory exactly as the package is structured internally. For files that you want in the root of the installation directory, you can use target="". – Adam Bezverkov Mar 28 '17 at 13:19
  • 1
    Is there a way to do this without directly referring to `bin\Release`? What if I want to create a pre-release package which happens to be a `Debug` build? – Rudey Sep 13 '17 at 09:09
  • 1
    `bin\Release\**\*.*` was just an example. You can swap it for whatever you want :) – khellang Sep 13 '17 at 09:11