4

When I try to use the built-in feature of creating Nuget packages in VS 2017 (for a .NET Standard class library), it doesn't include any dependencies (project references), it includes only the DLL of the current project...

Here is my project file:

<Project Sdk="Microsoft.NET.Sdk">
.
.
  <PropertyGroup>
    <TargetFrameworks>netstandard1.6;net47</TargetFrameworks>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <IncludeBuildOutput>True</IncludeBuildOutput>
    <IncludeContentInPack>True</IncludeContentInPack>
    <DevelopmentDependency>False</DevelopmentDependency>
  </PropertyGroup>
 .
 .
 </Project>

I tried different values for: DevelopmentDependency, IncludeContentInPack, IncludeBuildOutput, and it is the same.

I tried also on VS 2017 preview release as well.

Saw
  • 6,199
  • 11
  • 53
  • 104

2 Answers2

4

When I try to use the built-in feature of creating Nuget packages in VS 2017 (for a .NET Standard class library), it doesn't include any dependencies...

I aware of you want to pack nuget package include the referenced projects by Visual Studio 2017 directly. But I found that VS 2017 take the project references as dependencies when you pack package by VS 2017, I have not found a values to pack package include the referenced project as DLL file by VS directly.

As a workaround, you can use nuget and .nuspec file to include the referenced project, below is my .nuspec file:

<?xml version="1.0"?>
  <package >
    <metadata>
      <id>MyTestNuGetPackage</id>
      <version>1.0.0</version>
      <authors>Test</authors>
      <owners>Test</owners>
      <requireLicenseAcceptance>false</requireLicenseAcceptance>
      <description>Package description</description>
      <releaseNotes>Summary of changes made in this release of the package.
      </releaseNotes>
      <copyright>Copyright 2017</copyright>
      <tags>Tag1 Tag2</tags>
    </metadata>

    <files>
      <file src="bin\Debug\netstandard1.6\MyTestNuGetPackage.dll" target="lib\netstandard1.6" />
      <file src="bin\Debug\netstandard1.6\ReferencedProject.dll" target="lib\netstandard1.6" />
      <file src="bin\Debug\net47\MyTestNuGetPackage.dll" target="lib\net47" />
      <file src="bin\Debug\net47\ReferencedProject.dll" target="lib\net47" />
    </files>
  </package>

Then use the command: nuget pack .nuspec to create the nuget package.

enter image description here

For the detail info, you can refer to the Create .NET standard packages.

Julian
  • 33,915
  • 22
  • 119
  • 174
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
1

You must use the IncludeReferencedProjects switch with the NuGet pack command.

So, do something like:

nuget pack csprojname.csproj -IncludeReferencedProjects

Find the complete NuGet CLI here

Although NuGet picks up certain info about the package automatically(Assembly info as well as the output dll paths), anything that deals with packaging must be dealt with by either using the flags, or by creating a custom .NuSpec file.

Hope this helps!

BikerDude
  • 376
  • 2
  • 13
  • Thanks, I came across this, but there doesn't seem to be a way to pass extra command line parameters to the (csproj), actually, the packaging is done through (dotnet cli) and not (nuget cli) directly... – Saw Aug 14 '17 at 14:37
  • I tried to explore how to do this using the NuSpec file, but I was not able to get the exact option, I can pass a custom NuSpec file from the csproj... – Saw Aug 14 '17 at 14:39
  • Are you packing it through the Package Manager Console? – BikerDude Aug 14 '17 at 14:39
  • 1
    Not really, but rather through VS 2017 project properties (or by editing the project file), they've added many options to generate packages automatically when building, and they've added a (Pack) action when right-clicking on a .NET Standard project. – Saw Aug 14 '17 at 14:42
  • Seems to me that I myself am out of date haha. That right-click>pack option isn't out yet, at least in the VS17 pro v15.2, or I can't find it at least. I usually work with NuGet.exe or the PackageManagerConsole. If the native option can't be found, maybe work with a workaround using PackageManagerConsole? – BikerDude Aug 14 '17 at 14:48
  • 1
    It is available with .NET Standard class libraries (and maybe .NET Core), but not with .NET Framework normal projects. – Saw Aug 14 '17 at 14:50
  • Thanks for your time trying to answer though :) – Saw Aug 14 '17 at 14:50
  • Oh I see. I'll try looking into this further, Thank you so much for the appreciation! – BikerDude Aug 14 '17 at 14:53