【发布时间】:2015-08-12 15:10:35
【问题描述】:
我想创建一个 nuget 包(来自某个 c# 项目),但我不想嵌入生成的 dll,而只是嵌入一些静态文件。
我在 nuspec 文件的末尾添加了一个标签,但 nuget pack 命令继续将 project.dll 嵌入包中。 问题是我不想发布这个 dll。
有什么办法吗?
谢谢,
雷吉斯
【问题讨论】:
我想创建一个 nuget 包(来自某个 c# 项目),但我不想嵌入生成的 dll,而只是嵌入一些静态文件。
我在 nuspec 文件的末尾添加了一个标签,但 nuget pack 命令继续将 project.dll 嵌入包中。 问题是我不想发布这个 dll。
有什么办法吗?
谢谢,
雷吉斯
【问题讨论】:
是的。您可以创建一个简单引用内容文件的 .nuspec 文件。
你必须使用nuget pack MyPackage.nuspec
不要打包 .csproj 文件,因为这会导致 NuGet 包含已构建的程序集。
有关详细信息,请参阅http://docs.nuget.org/create/nuspec 参考。
【讨论】:
要将文件打包为内容,在 .nuspec 文档中列出文件时必须使用 target=content。
要创建“仅内容”nuget 包,您必须使用<files> 节点来列出文件。
<files> 节点必须是 <metadata> 节点的兄弟节点。
<file> 节点必须是 <files> 节点的子节点。
要将文件包含为内容,请将<file> 节点中的target 属性设置为“内容”。
例子:
<files>
<file src="{filePath}" target="content"/>
</files>
如前所述,您必须随后打包 .nuspec 文件而不是 .csproj 文件:
nuget pack *.nuspec
我在这里找到了target=content 技巧:
https://docs.microsoft.com/en-us/nuget/reference/nuspec#including-content-files
【讨论】:
对于 contentFiles,我在 nuspec 文件中使用这种方式:
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>DummyNuget</id>
<version>1.0.1-alpha</version>
<title>DummyNuget</title>
<authors>DummyNuget</authors>
<owners>DummyNuget</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>DummyNuget</description>
<releaseNotes></releaseNotes>
<copyright>2019</copyright>
<tags></tags>
<contentFiles>
<files include="**\*.*" buildAction="Content" copyToOutput="true" />
</contentFiles>
</metadata>
<files>
<file src="<path to files>\*.*" target="contentFiles\any\any" />
</files>
</package>
files 将本地文件放在 nuget 包中,然后 contentFiles 在元数据中将项目中的所有文件作为内容复制到输出
【讨论】: