Erik I
Erik I

Reputation: 1072

Keep documentation xml file while running publish with -c Release

I'm trying to build a project that includes swashbuckle and for troubleshooting I want to include swagger into a release build.

I've narrowed it down to this now:

When I run

dotnet publish -o ./out

the xml file ProjectName.xml is generated in the out folder and when I run

dotnet publish -o ./out -c Release

the xml file is not generated.

The csproj file looks like this:

<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>

and I'm pretty certain I can narrow it down even a bit further given time but I'm fairly new with dotnet and I also guess someone sees the problem already.

I'm looking for either a way to get this working or an explanation for why this is too wrong to be doable.

PS: Running on linux so no Visual Studio. Otherwise this could have been a possible solution for what I know: Swashbuckle + XmlComments work locally, but fail swagger generation on server

Upvotes: 3

Views: 1541

Answers (2)

Martin Ullrich
Martin Ullrich

Reputation: 100751

Add this to your csproj file instead of setting OutputPath or DocumentationFile:

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

Upvotes: 5

agua from mars
agua from mars

Reputation: 17444

Add in your .csproj :

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

Or remove the condition :

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

Upvotes: 2

Related Questions