Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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


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


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

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


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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

swaroop-sridharcommented, Jul 31, 2019


CopyToPublishDirectory setting determines the set of files to be published (the name is a bit misleading in the context of SingleFile publish.

Of these files, only those marked ExcludeFromSingleFile are left behind in the publish directory, and the rest are bundled into the single-file app.

When the single-file app is run, the settings file is extracted next to the app.dll (in appcontext.BaseDirectory) which is likely where the settings file is expected by the app.

So, this behavior is by design.

swaroop-sridharcommented, Jul 31, 2019

@xt0rted the publish settings provide the building blocks to either include or exclude a file from the single-file. In this case, ExcludeFromSingleFile=true is the correct setting for appsettings.json. I only meant to say that there may be additional work on behalf of the app (in general) due to the fact that the file is next to the single-file and not the app.dll. Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to handle Appsettings for .net core 3.1 self contained ...
The problem is that the appsettings.Production.json that is next to the exe does not get copied to the Temp folder. So the only...
Read more >
Create a single file for application deployment - .NET
Publish a single file application using the dotnet publish command. Add <PublishSingleFile>true</PublishSingleFile> to your project file.
Read more >
Single File Apps In .NET 6 - NET Core Tutorials
I'll note that when you are publishing a single file you *must* include the target OS type as the exe is bundled specifically...
Read more >
How to generate a self-contained .exe that can be run from ...
I see that the remote folder, where the executable was generated, contains a directory called "Application Files" whose content is attached.
Read more >
Keeping Content Out of the Publish Folder for WebDeploy
I've run into issues with keeping files from publishing with WebDeploy on numerous occasions. When working with large projects it's not ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found