【问题标题】:How to publish XML files from a NuGet package to an ASP.NET Core 2.1 application如何将 XML 文件从 NuGet 包发布到 ASP.NET Core 2.1 应用程序
【发布时间】:2020-03-02 12:46:47
【问题描述】:

我有一个 ASP.NET Core 2.1 应用程序(例如,MyWebApiApp),它引用了一个 NuGet 包(例如,MyPackage),其中包含在 Web API 中使用的模型。这些模型使用 XML cmets 进行记录,生成的 XML 文件与 NuGet 包一起发布(在 lib\netstandard2.0\MyPackage.xml 中)。

我想在 Swagger 中使用 XML 文档,所以我在 Startup.cs 中的SwaggerGenOptions 中添加以下内容:

c.IncludeXmlComments(Path.ChangeExtension(typeof(MyPackage.MyModel).Assembly.Location, ".xml"));

到目前为止,一切都很好。当我从 Visual Studio 2017 运行应用程序时,它成功地在 NuGet 包缓存中找到 XML 文档文件并生成 Swagger 文档。

现在我想发布网站。当我发布网站时:

  • 应用程序 (MyWebApiApp.xml) 的 XML 文档文件被复制到发布文件夹(我已将 <GenerateDocumentationFile>true</GenerateDocumentationFile> 包含在 MyWebApiApp.csproj 中)。
  • 但我的 NuGet 包 (MyPackage.xml) 中的 XML 文档文件没有被复制。

我尝试将this blog post 的咒语添加到MyWebApiApp.csproj,但没有成功。

【问题讨论】:

    标签: asp.net-core nuget-package asp.net-core-2.1 swashbuckle.aspnetcore


    【解决方案1】:

    我找到了解决方案here

    以下咒语需要添加到pubxml文件中:

    <Target Name="_ResolvePublishNuGetPackagePdbsAndXml"
          AfterTargets="RunResolvePublishAssemblies">
      <ItemGroup>
        <ResolvedFileToPublish
          Include="@(ResolvedAssembliesToPublish->'%(RootDir)%(Directory)%(Filename).pdb')"
          RelativePath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.pdb'))"
          DestinationSubPath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.pdb'))"
          Condition="'%(ResolvedAssembliesToPublish.PackageName)' != ''
                      and Exists('%(RootDir)%(Directory)%(Filename).pdb')" />
        <ResolvedFileToPublish
          Include="@(ResolvedAssembliesToPublish->'%(RootDir)%(Directory)%(Filename).xml')"
          RelativePath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.xml'))"
          DestinationSubPath="$([System.IO.Path]::ChangeExtension(%(ResolvedAssembliesToPublish.DestinationSubPath), '.xml'))"
          Condition="'%(ResolvedAssembliesToPublish.PackageName)' != ''
                      and Exists('%(RootDir)%(Directory)%(Filename).xml')" />
      </ItemGroup>
    </Target>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-29
      • 1970-01-01
      • 2018-07-30
      • 2019-04-08
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 2018-12-11
      相关资源
      最近更新 更多