Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create NuGet package from multiple projects, including NuGet dependencies

I have a solution where I want to create a NuGet package from two of the projects.

If it were just one project, I'd use the .csproj file to spec the NuGet packager, but since I want two different projects to go into the finished package, I can't do that.

I created a NuSpec file that referenced the DLLs from the two projects, and then packed it with the -IncludeReferencedProjects switch in the command line. This included the referenced projects from the same solution, but not any NuGet packages that were dependencies in the projects.

I tried referencing the new NuGet package in another solution, and the solution built and run, but encountered a FileNotFoundException at runtime when it was looking for the DLL from the NuGet packages that were dependencies in the NuGet package I just created.

I realize that I could include the NuGet dependencies in the NuSpec file, but that will become outdated the moment one of my projects adds another NuGet reference.

Is it possible to set up a NuSpec file so that it uses the .csproj files from both my projects and sets up the NuGet dependencies correctly, even when the projects are updated with new NuGet dependencies?

like image 616
Petter Brodin Avatar asked Jan 23 '15 10:01

Petter Brodin


1 Answers

Well, as far as I understand you have two projects, foo.csproj and bar.csproj. foo references bar.

You should use nuget pack foo.csproj -IncludeReferencedProjects (note that the pack command is applied on foo) as IncludeReferencedProjects option also adds the dependencies of the referenced projects.
This results in both foo.dll and bar.dll appearing in the lib folder of foo package. Also, both foo and bar dependencies will appear under the dependencies element.

like image 101
Peas Avatar answered Sep 21 '22 18:09

Peas