Runtime: dotnet publish single file does not copy appsettings.json

Created on 16 Aug 2019  路  7Comments  路  Source: dotnet/runtime

Steps to reproduce

When I try to run:
dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true
It gives me a single file exe however there is no appsettings.json file in sight.
How do I ensure that this file is copied across?

When I run the same command without the /p:PublishSingleFile=true switch then the appsettings.json file is included in the output directory.

Expected behavior

The /p:PublishSingleFile=true switch should ensure that the appsettings.json file is included as part of the publish.

Actual behavior

The appsettings.json file is not included in the output

Environment data

.NET core 3.0 preview 8

area-HostModel question

Most helpful comment

The behavior of the bundler is to pack all files in the publish directory -- except PDBs and files explicitly annotated to be left out -- into the bundle. Please see: https://github.com/dotnet/designs/blob/master/accepted/single-file/design.md#build-system-interface

So, for appsettings.json to be left beside the published app, is should be marked as <ExcludeFromSingleFile>true</ExcludeFromSingleFile> in the ASP.net project file that copies the content to the publish directory.

CC: @DamianEdwards

All 7 comments

What type of app is this? Is it an ASP.NET, console, or something else?
I would expect the file to be part of the .exe and when you run the app it will be unpacked into the temp folder which where the app runs. Is that not the case?

It's a console app.
The exe runs as if the appsettings.json is not there.
It's easily reproducible with a hello world app

Could you please share the piece of the code which reads the configuration? I just tried with an ASP.NET web app and the configuration works just fine - it reads values from appsettings.json even if it's a single-file where the appsettings.json is extracted to the temp directory.

Apologies, it does indeed look like the appsettings.json is in the zipped temp location.
I expected things to work slightly differently. i.e. that the appsettings.json should be at the same level as the single file exe as this is a config file whereas the temp directory should be for dependencies that we shouldn't need to worry about.

The behavior of the bundler is to pack all files in the publish directory -- except PDBs and files explicitly annotated to be left out -- into the bundle. Please see: https://github.com/dotnet/designs/blob/master/accepted/single-file/design.md#build-system-interface

So, for appsettings.json to be left beside the published app, is should be marked as <ExcludeFromSingleFile>true</ExcludeFromSingleFile> in the ASP.net project file that copies the content to the publish directory.

CC: @DamianEdwards

That's perfect. Thanks mate

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Timovzl picture Timovzl  路  3Comments

btecu picture btecu  路  3Comments

matty-hall picture matty-hall  路  3Comments

omajid picture omajid  路  3Comments

EgorBo picture EgorBo  路  3Comments