2017-08-14 46 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.

相关问题