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.
The /p:PublishSingleFile=true switch should ensure that the appsettings.json file is included as part of the publish.
The appsettings.json file is not included in the output
.NET core 3.0 preview 8
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
New link for the design document: https://github.com/dotnet/designs/blob/master/accepted/2020/single-file/design.md#build-system-interface
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