NuGet 包 XML 文档在 .NET Core 2.2 应用程序中不可见

NuGet package XML documentation not visible in .NET Core 2.2 app

我正在使用 NuGet package which has an XML documentation file

但是当我将包包含在 .NET Core 2.2 应用程序 中时,注释无法使用 IntelliSense.

为了能够使用 IntelliSense 查看文档,我在程序包或我的应用程序中是否遗漏了什么?

使用 VisualStudio 2017,Windows 10.

为清晰起见更新

NuGet 包是一个 .NET Standard 1.3 class 库。在 Visual Studio 构建项目时,我包含了生成包和文档文件的选项。在项目文件中,我看到以下 PropertyGroup:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DocumentationFile>C:\Users\[username]\[local path]\CommonEntities\CommonEntities\CommonEntities.xml</DocumentationFile>
</PropertyGroup>

打开包装后,在lib/netstandard1.3/目录下看到CommonEntities.xmlMakanalTech.CommonEntities.dll.

一起包含在内

但是,我想知道为什么 xml 文件删除了 MakanalTech.CommonEntities.xml 中的全名,因为它在项目中只是CommonEntities.xml 包中。也许这就是问题的原因?

问题是当我将包作为依赖项包含在另一个项目中时,XML comments/documentation 的 none 是可见的。所以我无法将鼠标悬停在类型上以查看其描述,如果我 peek definition none of the comments/documentation are in the definition.

Class 图书馆 产品 https://imgur.com/zbE7ngM(还不能 post 图片)

查看其他项目的定义: https://imgur.com/pwmvpX7

NuGet package XML documentation not visible in .NET Core 2.2 app

就像你发现的一样,“lib/netstandard1.3/ 目录中 CommonEntities.xml 与 MakanalTech.CommonEntities.dll.",lib文件夹下的.xml文件,然后根据文档From a convention-based working directory:

仅添加 .dll 文件作为参考,.xml 文件将复制到项目文件夹。这就是为什么 XML 文档在 .NET Core 2.2 应用程序中不可见的原因。

此外,由于您使用的是 .netstandard 项目,因此 .xml 文件将被 nuget issue 4837 自动复制到项目文件夹。

要解决此问题,我们必须使用选项 contentFiles 创建 .nuspec 文件以包含 .xml 文件并将此文件添加到项目中,请查看详细信息来自 .

但是如果你不想每次发布都手动编辑.nuspec,你可以使用post-build事件来自动打包nuget包,比如:

nuget pack "$(.NuspecFilePath)\xxx.nuspec" 

或者您可以直接从包中手动将 .xml 文件添加到项目中,该包位于路径中:C:\Users\<UserName>\.nuget\packages.

希望这对您有所帮助。

终于从 post 找到了问题。从 Visual Studio 2017 年开始,这似乎是错误的,无法正确自动地处理这个问题。

在 .csproj 文件中,我删除了 <DocumentationFile>[filepath-to-xml]</DocumentationFile> 并添加了 <GenerateDocumentationFile>true</GenerateDocumentationFile>

然后我重新打包了库,清除了我的 nuget 缓存,并在包含它的地方重建了新项目,现在我可以看到所有 XML 文档。