保留文档 xml 文件,同时 运行 使用 -c Release 发布

Keep documentation xml file while running publish with -c Release

我正在尝试构建一个包含 swashbuckle 的项目,为了进行故障排除,我想将 swagger 包含到发布版本中。

我现在将范围缩小到:

当我运行

dotnet publish -o ./out

xml 文件 ProjectName.xml 在 out 文件夹中生成,当我 运行

dotnet publish -o ./out -c Release

未生成 xml 文件。

csproj 文件如下所示:

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>netcoreapp2.1</TargetFramework>
        <OutputType>Exe</OutputType>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
        <OutputPath>bin\Debug\</OutputPath>
        <DocumentationFile>obj\Debug\ProjectName.xml</DocumentationFile>
    </PropertyGroup>

    <ItemGroup>
        <Folder Include="somefolder\" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.4" />
        ...
        <PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
        ...
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.3" />
        <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="3.0.0" />
    </ItemGroup>

</Project>

而且我很确定我 可以 在给定时间的情况下进一步缩小它的范围,但我对 dotnet 还很陌生,而且我猜有人已经看到了这个问题。

我正在寻找一种方法来实现这一点,或者寻找一种解释为什么这是错误的而不可行的原因。

PS:运行 在 linux 所以没有 Visual Studio。否则这可能是我所知道的可能的解决方案:

在您的 .csproj 中添加:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <OutputPath>bin\Release\</OutputPath>
    <DocumentationFile>obj\Release\ProjectName.xml</DocumentationFile>
</PropertyGroup>

或删除条件:

<PropertyGroup>
    <OutputPath>bin$(Configuration)\</OutputPath>
    <DocumentationFile>obj$(Configuration)\ProjectName.xml</DocumentationFile>
</PropertyGroup>

将此添加到您的 csproj 文件而不是设置 OutputPathDocumentationFile:

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