NuGet Pack providing Inconsistent Results when using csproj file - nuget

I'm creating nupkg files from csproj files using the following command:
nuget pack pathToMy.csproj
When I perform this command against one of my csproj files the nupkg contains all of the dependencies and all of the assemblies for my project references. However, when I run the same command against a csproj file in another solution I only get the dependencies. I don't get any my project referenced assemblies.
Any thoughts on this?

Did you remember to build the project first? If you haven't compiled the project, then NuGet pack won't pick up the project output.
You can also try:
nuget pack pathToMy.csproj -Build
That will cause NuGet to build your project first.

Related

Nuget restore is ignoring .xml files but downloading only .dll and .pdb files

The nuget package Project Xyz contains all xml files along with dll and pdb files. We are using this package Xyz in a different project Abc of a different solution.
We have a team city build setup for publishing the package Xyz to Proget feed(we use proget for private nuget packages repository).
We also have a Team City build setup to compile and deploy the Abc project. But, while compiling the build, when we restore the nuget package, it downloads only dll/pdb files but not xml files. In the build step of team city, we have runner type as dotnet and command as restore.
How do we make it restore xml files as well?
This is a follow up question to the above link? We followed below link to publish nuget package with xml files.
https://stackoverflow.com/a/63353505/5887074
Please note: Even though project level environment variables in team city has NUGET_XMLDOC_MODE=none, dot net restore is overriding environment variable for some reason with [Environment] NUGET_XMLDOC_MODE = skip

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.

How to add a folder to a nuspec file

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.

Multiple .nuspec files inside a project's directory?

Is it possible to have multiple nuspec files inside a single directory for the same project and still be able to merge the project and the specified nuspec file.
I wonder if something like this is possible:
nuget pack MyProject.csproj MyProject-x86.nuspec -prop Configuration=Release;Platform="x86"
nuget pack MyProject.csproj MyProject-AnyCpu.nuspec prop Configuration=Release
I need to be able to publish my project with more than one build configuration and thus I need to create different packages.
My very, very last resort will be to copy the csproj file at build time, rename it to "MyProject-x86.csproj" for example, run the nuget pack and then delete it. I would hate to do that and I am looking for alternatives.
Thanks.
When calling NuGet pack, you cannot pass more than a single csproj or nuspec file. Note the pipe in the command line help (to indicate one or the other):
usage: NuGet pack <nuspec | project> [options]
You could create another csproj stripped down to just an import element to the main csproj (i.e. the one you work from in Visual Studio), override the values of property group items as needed, and/or have matching .nuspec files.