将.NET Standard库打包为Nuget包,并包括所有项目依赖项/引用 [英] Package .NET Standard library as Nuget package and include all project dependencies / references

查看:174
本文介绍了将.NET Standard库打包为Nuget包,并包括所有项目依赖项/引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用在VS 2017中创建Nuget包的内置功能时(对于.NET Standard类库),它不包含任何依赖项(项目引用),它仅包含当前的DLL项目...

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

这是我的项目文件:

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

我尝试了不同的值:DevelopmentDependency,IncludeContentInPack,IncludeBuildOutput,并且相同。

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

我也在VS 2017预览版上也尝试过。

I tried also on VS 2017 preview release as well.

推荐答案


当我尝试使用在VS 2017中创建Nuget包的内置功能(用于.NET Standard类库)时,它不包含任何依赖项...

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

我知道您想打包nuget包,其中包括Visual Studio 2017直接引用的项目。但是我发现当您通过VS 2017打包软件包时,VS 2017将项目引用作为依赖项,但我没有发现要打包的值包含被VS直接作为DLL文件包含引用的项目。

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.

作为解决方法,您可以使用nuget和.nuspec文件包含引用的项目,以下是我的.nuspec文件:

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>

然后使用命令: nuget pack .nuspec 创建nuget包。

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

详细信息,您可以参考创建.NET标准软件包。

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

这篇关于将.NET Standard库打包为Nuget包,并包括所有项目依赖项/引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆