Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include referenced project in nuget package

I have a solution with 3 projects (using netstandard1.4). Project A contains shared code. Project B is a server side library and project C is a client side library. Project B and C include project A as project reference.

Now I want to publish project B and project C as a nuget package.

The Problem is the nuget packages for project B and C do not contain the code / dll from project A. It looks like project B and C want project A also as a nuget package.

How can I pack the project B and C as standalone nuget packages? I don’t want to publish project A as a nuget package.

like image 677
ctron Avatar asked Jun 27 '17 15:06

ctron


1 Answers

How can I pack the project B and C as standalone nuget packages? I don’t want to publish project A as a nuget package.

Since you are using .NET Standard 1.4, you could not use the direct way "dotnet pack" to include the project references. Because dotnet pack will pack only the project and not its P2P references, you can get the detail info from the document dotnet-pack and the issue on GitHub:

NuGet dependencies of the packed project are added to the .nuspec file, so they're properly resolved when the package is installed. Project-to-project references aren't packaged inside the project. Currently, you must have a package per project if you have project-to-project dependencies.

If you want to pack project B and C contain the code / dll from project A, you can use NuGet.exe to create the package B and C by adding project reference assemblies to the .nuspec file:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>TestProjectB</id>
    <version>1.0.0</version>
    <authors>Tester</authors>
    <owners>Tester</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Package description</description>
    <releaseNotes>Test sample for netstandard package.</releaseNotes>
    <copyright>Copyright 2017</copyright>
    <tags>Tag1 Tag2</tags>
  </metadata>
<files>
    <file src="bin\Debug\netstandard1.4\TestProjectB.dll" target="lib\netstandard1.4\TestProjectB.dll" />
    <file src="bin\Debug\netstandard1.4\TestProjectA.dll" target="lib\netstandard1.4\TestProjectA.dll" />
</files>
</package>

In this case, you can pack the project B and C as standalone nuget packages, do not need publish project A as a nuget package.

like image 81
Leo Liu-MSFT Avatar answered Sep 23 '22 07:09

Leo Liu-MSFT