当我尝试使用在VS 2017中创建Nuget包的内置功能时(对于.NET标准类库),它不包含任何依赖项(项目引用),它只包含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预览版。
答案 0 :(得分:2)
当我尝试使用在VS 2017中创建Nuget包的内置功能时(对于.NET标准类库),它不包含任何依赖项......
我知道你想直接包装nuget包,包括Visual Studio 2017引用的项目。但我发现VS 2017将项目引用作为依赖项当你通过VS 2017打包时,我没有找到一个值来打包包括引用项目作为DLL文件由VS直接。
作为一种解决方法,您可以使用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包。
有关详细信息,请参阅Create .NET standard packages.
答案 1 :(得分:1)
您必须将IncludeReferencedProjects
开关与NuGet pack命令一起使用。
所以,做一些像:
nuget pack csprojname.csproj -IncludeReferencedProjects
找到完整的NuGet CLI here
虽然NuGet会自动获取有关包的某些信息(程序集信息以及输出dll路径),但是处理打包的任何内容都必须通过使用标志或创建自定义.NuSpec文件来处理。
希望这有帮助!