Reputation: 21017
I'm working on a project in Visual Studio that is split up into three different projects:
The WebApplication
uses the Domain
project where its entity classes are stored and some other "core" objects and interfaces.
The SDK
project is something we give to 3rd party users. It makes API calls to our WebApplication
project. The SDK
project also makes use of the Acme.Domain
project.
Now here comes the problem.
We create a NuGet package for our Acme.SDK
. But because the Acme.SDK
also uses the Acme.Domain
project, so we also need to package that as a NuGet package.
What I'd like to have is just one NuGet package and still be able to reference both the classes from Acme.SDK
and Acme.Domain
from that one NuGet package instead of two loose NuGet packages.
Is this possible? And of so, how can I do this?
Upvotes: 3
Views: 2983
Reputation: 20312
Yes. As you know, NuGet can create a package directly from a .csproj file. This is is basically the "automatic" mode. It's simple, but also has limitations.
You can also create a .nuspec file that allows you the explicitly state how you want to build your package. This can include multiple assemblies, dependencies, target different frameworks, etc.
First create a folder named nuspec in the root of your solution.
Open a command line in the nuspec folder.
Type: nuget spec MyPackage
<= use whatever your package id should be
This will create a MyPackage.nuspec file. Edit this file. You'll see a bunch of boilerplate code there. Update the values appropriately.
NOTE: Once you start using an explicit .nuspec file, you will have to maintain these values (like Version number) as they will no longer pull from the .csproj file.
The main part you need to add is a <files/>
section. Also make sure that you include the dependencies needed by BOTH your projects.
Here is a sample .nuspec file:
<?xml version="1.0"?>
<package >
<metadata>
<id>MyPackage</id>
<version>1.0.0</version>
<authors>Author Names</authors>
<owners>Owner Names</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>MyPackage description</description>
<releaseNotes>Initial version.</releaseNotes>
<copyright>Copyright 2015</copyright>
<!-- add dependencies here
<dependencies>
<dependency id="SomePackage.Id" />
</dependencies>
-->
</metadata>
<files>
<file src="..\ProjectA\bin\Debug\ProjectA.dll" target="lib\net45" />
<file src="..\ProjectB\bin\Debug\ProjectB.dll" target="lib\net45" />
</files>
</package>
Notice how the files section references the actual assemblies you want to include in your package.
Once you've edited the .nuspec file, you need to create the package.
From the command line, type: nuget pack MyPackage.nuspec
It should then create a MyPackage.1.0.0.nupkg file ready for upload to NuGet.org.
Here is the documentation for the Nuspec format: http://docs.nuget.org/Create/Nuspec-Reference
Upvotes: 5