简体   繁体   中英

Package .NET Standard library as Nuget package and include all project dependencies / references

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.

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.

在此处输入图片说明

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

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM