runtime icon indicating copy to clipboard operation
runtime copied to clipboard

dotnet publish single file does not copy appsettings.json

Open AhmadChaker opened this issue 7 years ago • 7 comments

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

AhmadChaker avatar Aug 15 '19 23:08 AhmadChaker

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?

vitek-karas avatar Aug 16 '19 08:08 vitek-karas

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

AhmadChaker avatar Aug 16 '19 11:08 AhmadChaker

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.

vitek-karas avatar Aug 16 '19 13:08 vitek-karas

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.

AhmadChaker avatar Aug 19 '19 00:08 AhmadChaker

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

swaroop-sridhar avatar Aug 20 '19 01:08 swaroop-sridhar

That's perfect. Thanks mate

AhmadChaker avatar Aug 20 '19 06:08 AhmadChaker

New link for the design document: https://github.com/dotnet/designs/blob/master/accepted/2020/single-file/design.md#build-system-interface

SeanFeldman avatar Mar 24 '20 04:03 SeanFeldman