2

I'd begin with saying that I never had any experience with managing NuGet packages, even the simplest ones. However, I'm planning to use it in my next project, which design could rely on the answers to my question.

For a better understanding of the problem, let's assume we have the following projects, all under one solution:

  • Core
  • Foo
  • Bar

Both Foo and Bar depend on Core, but not on each other.
As such, I'd like to create one nuget package for the Foo + Core combination, and one for the Bar + Core combination, without separating them to different solutions.

Is this scenario possible?

Timor Gruber
  • 312
  • 2
  • 4
  • 15
  • 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. Probable duplicate:https://stackoverflow.com/questions/16173568/build-nuget-package-automatically-including-referenced-dependencies – Leo Liu Aug 08 '17 at 03:51

1 Answers1

2

Yes, your scenario is possible. NuGet package creation doesn't depend on the solution the project belongs to. You can either define your own nuspec file to pack a package or use a csproj file to do so. Look at: https://learn.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference

Note: NuGet primarily packes .dll files into a package. Even if you use .csproj files, it looks at the and picks up the .dll from that location. You can choose to store the Sourcecode using the NuSpec file though.

For a NuSpec file:

  • What you want to pack entirely depends on you and you can what goes in, in the things in a NuSpec file.

For a .csproj file(I think this is what you should use):

  • Use the nuget pack <nuspecPath | projectPath> [options] command IncludeReferencedProjects as an option, and projectpath for Foo and Bar individually. This would create two separate NuGet packages which fulfill your need.
BikerDude
  • 376
  • 2
  • 13
  • Awesome! Let me know how it goes. Also, try using NuGet spec to autogenerate a NuSpec file in case you want to pursue that route. – BikerDude Aug 07 '17 at 17:51
  • @TimorGruber Please let me know if you solved the problem! Otherwise I can possibly help you out further. – BikerDude Aug 09 '17 at 17:11
  • 1
    Finally got time to check your solution, and guess what? It absolutely works! I used the *.csproj* approach, although I'm convinced that it's possible and maybe even better to use the **NuSpec** file. I marked your answer as the answer to this question, thank you very much. – Timor Gruber Aug 09 '17 at 18:26
  • Awesome to here! Yeah the NuSpec file approach gives you far more options, you can even pack useless things not part of any project. Guess what: Whenever you use a nuget pack .csproj, it automatically creates a nuspec file, and creates a package using that. This nuspec can be found when you unarchive the .nupkg file. Also: Try using : `NuGet Spec ` command when you want to create the nuspec file using the csproj metadata. Also, thanks for marking it as an answer, I CAN NOW COMMENT **EVERYWHERE** – BikerDude Aug 09 '17 at 18:31