How to add a folder to a nuspec file - nuget

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!?

I don't know OctoPack, but with nuget.exe, packaging is done in two steps:
Either create a .nuspec manually, or generate one from a .csproj or existing assembly (see nuget spec in the docs).
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.

Related

Should I publish the nuspec file in a repository?

When creating an open source library on GitHub or another public website, should I publish the .nuspec file that describes the corresponding NuGet package?
I've done this a couple of times (since no API key or other sensitive information is included in the .nuspec file) in order to allow myself to easily publish subsequent versions without keeping private file, and to allow other people to fork it and add their own descriptions easily. However, the developers of many top packages don't seem to publish .nuspec files in their repositories (sometimes they publish NuGet.exe along with a .targets file, and so on), so I'm thinking that maybe I'm doing something wrong.
The package authoring should be considered part of the source code since it is a required asset to build the fully usable output.
Some projects use special msbuild-based tooling to create the nuspec file during the build so it seems like there is none in the repository. the new "SDK-based" projects (e.g. .NET Standard libraries) have integrated nuget tooling to be able to create a nupkg file from the csproj without the need to create a nuspec file. This tooling is also being adopted by some popular packages (e.g. Newtonsoft.Json).

Specify Octopack nuget package file's target path

I found OctoPack to be incredibly straight forward when creating .nupkg nuget package files, however I I'd like the .nuspec file included (currently is placed in another folder such as obj/octopackage or something), and all the dlls should be placed inside a lib/net452 folder so that the general structure appears as such:
Currently everything that should be in the lib/net452 folder is simply placed in the root, along with _rels and package, and as mentioned the .nuspec file is missing.
Either the documentation is a little sparse or I've completely missed how to do this in my debugging mental haze. Anyone know how to specify to OctoPack where, specifically, to place the compiled output within the .nupkg file?
To create your NuGet package, you should be using nuget.exe, not OctoPack. I'll explain why in a minute.
The .nuspec file serves as the "blueprint" for your NuGet package (.nupkg). So the short answer is to simply specify the location in your .nuspec file, using the target attribute of the <files> element. Details can be found on the NuGet site, but it would look something like this:
<files>
<file src="bin\$configuration$\*.dll" target="lib\net452\" />
</files>
There are a number of ways to call nuget.exe in a post-build step; many are explained on the NuGet site as well.
OctoPack is not meant to create packages for nuget.org; it is designed specifically to create packages for Octopus Deploy. It creates packages one of two ways:
If there is a web.config file present, OctoPack assumes that the project is a web project, and packages the output accordingly. It uses the project file to determine which items are marked as content, and which are not (although it will always grab web.config transformation files).
Otherwise, OctoPack assumes that the project is an executable, or a component, and simply packs whatever it finds in the output folder (usually \Debug\bin or \Release\bin). This is the behavior that you're seeing.
Since OctoPack uses nuget.exe under the hood, a .nuspec file will override both of the above cases. So while you could use OctoPack to create your NuGet package, it's more appropriate to use nuget.exe.

NuGet - Create nuspec with dependencies of packages.config

You can create a .nuspec file from a .csproj using simply nuget.exe spec from within the project folder.
However, the NuGet packages used by the project are not added to the <dependencies> section in the resulting .nuspec file.
Is there some way to make this happen automatically, seems like an obvious need?
At the moment I just copy paste a chunk from the packages.config file and tweak it a bit.
You need to run nuget pack command with -IncludeReferencedProjects parameter. Then referenced projects will be included in target .nuspec file.
You could check that by renaming generated .nupkg to .zip, open it and analyze inner .nuspec file where dependencies will be listed.
Read here: Nuget create a package
There's another case that you doing - it's to add the dependecy manually - this way you could set version attribute on referenced project. You could set it to minimum version, maximum version, etc...
Read here: Nuspec file reference

.nuget include file from other project

I have three visual studio database projects with .sql files. Instead of publishing the projects to a database, the SQL needs to be executed at a specific moment.
I added another project to package everything into one nuget package (including some generic scripts). So the .nuspec file should specify the SQL files that need to be included.
<file src="..\otherproject\code.sql" target="Content" />
We use TeamCity to build our projects and Octopus Deploy to pack the nuget packages. When TeamCity tries to build the package OctoPack says it can't find the file:
error OCTONUGET: File not found:
'..\otherproject\code.sql'.
I've checked, the file is present on the build server on the requested location.
How to access the parent folder? Or is there another way to include files from other projects?
This code is perfectly fine. My .nuspec file was named like the solution instead of the project.

can you deploy data and no assemblies via a nuget package?

is it possible to use nuget to deploy test data instead of dlls?
we have some largish test data files which I don't want to keep in our git repository and I am wondering if we could deploy these to the test projects during the build by including them in a nuget package which gets installed during the build.
Is this possible?
Yes, but, without knowing a few more details about how your project is structured, it's difficult to tell you exactly how you would do this.
If you just want to copy your data files into a directory in your test project, you can just put the files in a content folder in a NuGet package, and it will copy them to your project automatically, much in the same way that it would copy DLLs. If this is all you need, you can create a package like this in a few minutes.
If you need to deploy the test data files to a directory outside of your project directory, or manipulate the file names or contents, you can do this as well. I usually create a tools package to do this.
I put the files I want to copy into a tools directory in my package, and then create a simple init.ps1 or install.ps1 script to do whatever copying and file manipulation tasks are required.
If you are intimidated by the prospect of creating packages from scratch, you may find NuGet Package Explorer helpful. You can create a content folder and drag the content you want to deploy into it:
http://npe.codeplex.com/