[英]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.