【问题标题】:Package .NET Standard library as Nuget package and include all project dependencies / references将 .NET Standard 库打包为 Nuget 包并包含所有项目依赖项/引用
【发布时间】:2018-01-22 10:20:55
【问题描述】:

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

这是我的项目文件:

<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,都是一样的。

我也尝试过 VS 2017 预览版。

【问题讨论】:

    标签: .net visual-studio nuget .net-core visual-studio-2017


    【解决方案1】:

    您必须将IncludeReferencedProjects 开关与 NuGet pack 命令一起使用。

    所以,请执行以下操作:

    nuget pack csprojname.csproj -IncludeReferencedProjects
    

    找到完整的 NuGet CLI here

    虽然 NuGet 会自动获取有关包的某些信息(程序集信息以及输出 dll 路径),但处理打包的任何内容都必须通过使用标志或创建自定义 .NuSpec 文件来处理。

    希望这会有所帮助!

    【讨论】:

    • 谢谢,我遇到了这个,但似乎没有办法将额外的命令行参数传递给(csproj),实际上,打包是通过(dotnet cli)而不是(nuget cli) 直接...
    • 我试图探索如何使用 NuSpec 文件执行此操作,但我无法获得确切的选项,我可以从 csproj 传递自定义 NuSpec 文件...
    • 你是通过包管理器控制台打包的吗?
    • 不是真的,而是通过 VS 2017 项目属性(或通过编辑项目文件),他们添加了许多选项以在构建时自动生成包,并且他们添加了 (Pack) 操作右键单击 .NET Standard 项目时。
    • 它适用于 .NET Standard 类库(可能还有 .NET Core),但不适用于 .NET Framework 普通项目。
    【解决方案2】:

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

    我知道你想打包 nuget 包,直接包含 Visual Studio 2017 引用的项目。但是我发现VS 2017在你用VS 2017打包包时将项目引用作为依赖项,我没有找到一个值来打包包包含引用的项目作为DLL文件直接由VS。

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

    <?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 包。

    详细信息可以参考Create .NET standard packages.

    【讨论】:

      猜你喜欢
      • 2019-03-19
      • 2023-03-09
      • 1970-01-01
      • 2019-09-16
      • 1970-01-01
      • 2019-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多