Package .NET Standard library as Nuget package and

2019-08-21 08:21发布

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.

2条回答
闹够了就滚
2楼-- · 2019-08-21 09:06

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!

查看更多
该账号已被封号
3楼-- · 2019-08-21 09:08

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 .nupsec 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.

查看更多
登录 后发表回答