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

查看:41
本文介绍了将 .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="binDebug
etstandard1.6MyTestNuGetPackage.dll" target="lib
etstandard1.6" />
      <file src="binDebug
etstandard1.6ReferencedProject.dll" target="lib
etstandard1.6" />
      <file src="binDebug
et47MyTestNuGetPackage.dll" target="lib
et47" />
      <file src="binDebug
et47ReferencedProject.dll" target="lib
et47" />
    </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天全站免登陆