簡體   English   中英

將 .NET Standard 庫打包為 Nuget 包並包含所有項目依賴項/引用

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

當我嘗試使用在 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 預覽版。

當我嘗試使用在 VS 2017 中創建 Nuget 包的內置功能(對於 .NET Standard 類庫)時,它不包含任何依賴項......

我知道你想直接打包 nuget 包,包括 Visual Studio 2017 引用的項目。 但是我發現VS 2017在VS 2017打包包時將項目引用作為依賴項,我還沒有找到直接通過VS打包包含引用項目作為DLL文件的值。

作為一種解決方法,您可以使用 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 包。

在此處輸入圖片說明

有關詳細信息,您可以參考創建 .NET 標准包。

您必須將IncludeReferencedProjects開關與 NuGet pack 命令一起使用。

因此,請執行以下操作:

nuget pack csprojname.csproj -IncludeReferencedProjects

此處找到完整的 NuGet CLI

盡管 NuGet 會自動獲取有關包的某些信息(程序集信息以及輸出 dll 路徑),但必須通過使用標志或創建自定義 .NuSpec 文件來處理任何與打包有關的問題。

希望這有幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM