Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet publish single file does not copy appsettings.json #3734

Closed
AhmadChaker opened this issue Aug 15, 2019 · 7 comments
Closed

dotnet publish single file does not copy appsettings.json #3734

AhmadChaker opened this issue Aug 15, 2019 · 7 comments
Assignees
Labels
area-HostModel Microsoft.NET.HostModel issues question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@AhmadChaker
Copy link

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

@vitek-karas
Copy link
Member

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?

@AhmadChaker
Copy link
Author

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

@vitek-karas
Copy link
Member

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.

@AhmadChaker
Copy link
Author

AhmadChaker commented Aug 19, 2019

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.

@swaroop-sridhar swaroop-sridhar self-assigned this Aug 20, 2019
@swaroop-sridhar
Copy link
Contributor

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

@AhmadChaker
Copy link
Author

That's perfect. Thanks mate

@SeanFeldman
Copy link

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

@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-HostModel Microsoft.NET.HostModel issues question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

4 participants