appsettings files aren't included in publish folder when using PublishSingleFile
See original GitHub issueI’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">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
</PropertyGroup>
<ItemGroup>
<None Update="appsettings*.json" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
</ItemGroup>
</Project>
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">
<ItemGroup>
<None Update="appsettings*.json" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" ExcludeFromSingleFile="True" />
</ItemGroup>
</Project>
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:
- Created 4 years ago
- Comments:6 (5 by maintainers)
@xt0rted:
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
(inappcontext.BaseDirectory
) which is likely where the settings file is expected by the app.So, this behavior is by design.
@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 forappsettings.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.