Nuget packaging multiple projects

I have noticed a few people struggle when it comes to packaging multiple projects that exist in a single solution and I had a similar problem at work. Taking a look on SO you can easily find the work-around which is to use an additional Nuget command :

-IncludeReferencedProjects

Now this works when you want to package up a project that references other projects and so on. But what if you had, lets say, 3 projects A,B and C and all 3 projects had to be packaged together? By the way, allowing them to be packaged separately just wasn’t an option.

  • Project A does not reference anything.
  • Project B references Project A
  • Project C references Project A

In this case what do we do? We want to package project A, but the above command wont work since A has no references. This means B and C wont be included.

Worry not as Nuget has us covered.

  • Got to the root directory of your solution.
  • Add a nuspec file, you can find a template pretty much anywhere.
  • Add the following lines after the metadata section
<files>
    <file src="..\src\ProjectA\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0\" />
    <file src="..\src\ProjectB\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0\" />
    <file src="..\src\ProjectC\bin\Debug\netstandard2.0\*.dll" target="lib\netstandard2.0\" />
</files>

All this does is tell Nuget exactly which dll’s you want packaged up. Turned out to be pretty simple in the end.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s