如何将类库的 Xml 文档包含在 NuGet 包中?
我正在为 C# 类库创建 NuGet 包,并且希望在该库中包含生成的 Xml 文档。这是我的 nuspec 文件:
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>MyLibrary</id>
<version>1.0.0.0</version>
<authors>John Nelson</authors>
<language>en-US</language>
<description>A C# class library</description>
</metadata>
<files>
<file src="..\..\build\MyLibrary.dll" target="lib\Net40" />
<file src="..\..\build\MyLibrary.xml" target="lib\Net40" />
</files>
</package>
当我 使用此命令构建包:
nuget pack MyLibrary.nuspec
它会产生错误。如果我删除该行:
<file src="..\..\build\MyLibrary.xml" target="lib\Net40" />
NuGet.exe 成功创建了 nupkg.txt 文件。我什至可以解压缩包,并验证内容是否正确。我做错了什么? xml 文件是否应该进入不同的目标目录?
I am creating a NuGet package for a C# class library, and I would like to include generated Xml Documentation with the library. This is my nuspec file:
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>MyLibrary</id>
<version>1.0.0.0</version>
<authors>John Nelson</authors>
<language>en-US</language>
<description>A C# class library</description>
</metadata>
<files>
<file src="..\..\build\MyLibrary.dll" target="lib\Net40" />
<file src="..\..\build\MyLibrary.xml" target="lib\Net40" />
</files>
</package>
When I build the package with this command:
nuget pack MyLibrary.nuspec
It generates an error. If I remove the line:
<file src="..\..\build\MyLibrary.xml" target="lib\Net40" />
NuGet.exe successfully creates the nupkg. I can even unzip the package, and verify that the contents are correct. What am I doing wrong? Should the xml file go into a different target directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是我没有检查我正在使用的构建配置的“生成 Xml 文档”。 nuspec 是正确的。
The problem was that I didn't check "Generate Xml Documentation" for the build configuration I was using. That nuspec is correct.
在 .NET Core/Standard 中,您可以通过编辑项目 XML 文件来完成此操作,例如:
这会将文档作为 XML 文件输出到输出程序集旁边。
编辑:
作为旁注,一旦您启用
GenerateDocumentationFile
,您可能会因未添加完整文档标签而收到有关公共方法的大量警告。如果您想禁用这些警告,只需在PropertyGroup
中添加:In .NET Core/Standard you can do this by editing the project XML file, for example:
This will output the documentation as an XML file next to your output assembly.
EDIT:
As a side note once you enable
GenerateDocumentationFile
you will probably get lots of warnings on your public methods for not having added full documentation tags. If you want to disable these warnings simply add in thePropertyGroup
:最简单的解决方案是简单地添加@bytedev 答案的前半部分。这默认为正确的位置并将被正确打包。
The easiest solution is to simply add the first half of @bytedev's answer. This defaults to the correct location and will be packaged correctly.