Skip to content

appsettings files aren't included in publish folder when using PublishSingleFile #3469

@xt0rted

Description

@xt0rted

I'm testing out the /p:PublishSingleFile=true option and it's working well so far, but my appsettings.json doesn't get included in the publish folder. If I don't use PublishSingleFile=true then the file does get copied to the publish folder.

I'm using the following to publish:

dotnet publish -c Release /p:PublishSingleFile=true /p:PublishTrimmed=true

In my .csproj I have the following but it doesn't seem to have an effect when PublishSingleFile=true:

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RuntimeIdentifier>win10-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <None Update="appsettings*.json" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
  </ItemGroup>

</Project>

I'm using SDK version 3.0.100-preview7-012821.

Current workaround

After looking through some GitHub issues I found mention of ExcludeFromSingleFile. If I add that to my appsettings entry then the file gets included in the single file publish results.

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

  <ItemGroup>
    <None Update="appsettings*.json" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" ExcludeFromSingleFile="True" />
  </ItemGroup>

</Project>

Since these files are the standard way of handling settings in a file I'd assume they would be included in the publish results without any extra settings, or at least if CopyToPublishDirectory is set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions