【问题标题】:Specify deployment path for XML documentation output path指定 XML 文档输出路径的部署路径
【发布时间】:2020-12-14 11:19:45
【问题描述】:

我正在为我的 .NET Core Web api 项目使用 Swashbuckle.AspNetCore 包。我想添加 XML cmets 支持,所以我必须在应用程序设置中将 Build => Output => XML 文档文件设置为 true

不幸的是,自动生成的路径是绝对的

C:\Users\myUser\...\repository\solution\project\project.xml

所以这只适用于我的机器。有没有办法使用占位符?例如

{{pathToProject}}\project.xml

所以它在本地调试和部署时工作?

【问题讨论】:

    标签: c# visual-studio .net-core


    【解决方案1】:

    点击Browse...按钮,选择项目路径下的文件夹,如bin\debug

    然后检查XML documentation file。它会生成一个相对路径。

    【讨论】:

    • 这条路径是否适用于所有场景?例如发布、部署、...
    • 为了让它工作我必须设置这个输出路径“bin\Debug\netcoreapp3.1\”所以我不确定这是否涵盖了所有的东西
    【解决方案2】:

    有一种简单的方法可以在相对路径中生成 XML 文档文件。只需将DocumentationFile 属性设置为true

    <PropertyGroup>
      <GenerateDocumentationFile>true</GenerateDocumentationFile>
    </PropertyGroup>
    

    这已记录在此处的另一个 StackOverflow 答案中: https://stackoverflow.com/a/47118584/19112

    然后您可以设置您的SwaggerGenOptions 以使用您的 XML 文档,如下所示:

    // Set the comments path for the Swagger JSON and UI.
    var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
    var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
    options.IncludeXmlComments(xmlPath);
    

    如这里的示例所示: https://code-maze.com/swagger-ui-asp-net-core-web-api/#ExtendingDocumentation

    【讨论】:

      【解决方案3】:

      您可以更改 project.csproj,然后在 debug[desired location] 文件夹中使用自定义名称获取 xml 文件。我注释掉了默认行。。 p>

      <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
          <!--<DocumentationFile>C:\Users\furkan.katman\source\repos\WebApplication1\WebApplication1\WebApplication1.xml</DocumentationFile>-->
            <DocumentationFile>bin\Debug\ProjectName.XML</DocumentationFile>
        </PropertyGroup>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-02
        相关资源
        最近更新 更多