2017-08-14 186 views
0

當我嘗試使用在VS 2017(對於.NET標準類庫)中創建Nuget包的內置功能時,它不包含任何依賴關係(項目引用),它僅包括當前項目的DLL ...將.NET標準庫作爲Nuget包打包,幷包含所有項目依賴關係/引用

這裏是我的項目文件:

<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預覽版上試過。

回答

1

您必須使用帶有NuGet pack命令的IncludeReferencedProjects開關。

所以,做這樣的事情:

nuget pack csprojname.csproj -IncludeReferencedProjects 

找到完整的NuGet CLI here

雖然的NuGet拿起有關自動包裝某些信息(議會信息以及DLL的輸出路徑),任何事情處理包裝必須通過使用標誌或通過創建自定義的.NuSpec文件來處理。

希望這會有所幫助!

+0

謝謝,我遇到了這一點,但似乎沒有成爲一個方式,額外的命令行參數傳遞給(的csproj ),實際上,包裝是通過(dotnet cli)而不是(nuget cli)直接完成的... –

+0

我試圖探索如何使用NuSpec文件來做到這一點,但我無法得到確切的選項,我可以從csproj傳遞一個定製的NuSpec文件... –

+0

您是否通過軟件包管理器控制檯打包它? – BikerDude

2

當我嘗試使用內置在2017年VS創建的NuGet包(用於.NET標準類庫)的功能,它不包含任何依賴...

我意識到你想要包裝nuget包,直接包含Visual Studio 2017引用的項目。但是我發現當VS包裝到VS 2017時,VS 2017將項目引用作爲依賴關係,我沒有發現一個包裝包的值直接包含VS作爲DLL文件引用的項目。

作爲一種變通方法,您可以使用的NuGet和.nuspec文件,包括引用的項目,下面是我的.nupsec文件:

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

enter image description here

具體交易信息,您可以參考Create .NET standard packages.