在 csproj 文件中,我通过以下标签启用了 XML 文档生成:
<PropertyGroup>
<DocumentationFile>bin\xml\Project.Api.xml</DocumentationFile>
<NoWarn>1701;1702;1705;1591;1573</NoWarn>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
这有效并正确构建 xml 文档。现在我需要将这个 XML 文件与应用程序一起分发(用于 Swagger 支持等)。所以我添加了以下内容:
<ItemGroup>
<None Update="bin\xml\Project.Api.xml">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</None>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
但是,当我发布到文件夹(或天蓝色)时,找不到 XML 文档。
我错过了什么?
以下内容适用于您的场景(至少在发布到文件夹时):
<!-- Run before PrepareForPublish target -->
<Target Name="CopyDocumentationFile" BeforeTargets="PrepareForPublish">
<ItemGroup>
<DocFile Include="$(DocumentationFile)" />
</ItemGroup>
<!--just copy doc file to target location -->
<Copy SourceFiles="@(DocFile)" DestinationFolder="$(PublishDir)" SkipUnchangedFiles="true" />
</Target>
Run Code Online (Sandbox Code Playgroud)
在这里您可以找到有关如何将自定义文件包含到发布输出中的文档。他们使用更复杂的方式,但只是多一点。