5
votes

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?

1
Can you please describe the relations between your projects? Is one project references the other? Also, are there only two projects in the solution, or are there more and you need them to be packed as well?Peas
One references the other. There are other projects in the solution, but they're not needed as part of the package. If, however, they're referenced by the projects included in the package, that's solved by using the -IncludeReferencedProjects parameter when packing the package. The problem is not the intra-solution references, but making sure that all required NuGet packages are correctly referenced.Petter Brodin

1 Answers

6
votes

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.