user1947960
user1947960

Reputation: 298

How do I publish a separate appsettings.json file when publishing a single .exe?

I have a console App with a config file. When I publish using the new PublishSingleFile setting in the .proj it publishes the app as one file (good) but it also adds the appsettings to that .exe.

This means it isn't really a config file at this point and more a file hard coded values.

How do I publish with a separate config file?

current .proj settings

<PropertyGroup>
   <OutputType>Exe</OutputType>
   <TargetFramework>netcoreapp3.0</TargetFramework>
   <PublishReadyToRun>true</PublishReadyToRun>
   <PublishSingleFile>true</PublishSingleFile>
   <PublishTrimmed>true</PublishTrimmed>
   <RuntimeIdentifier>win-x64</RuntimeIdentifier>
 </PropertyGroup>

Upvotes: 2

Views: 1841

Answers (1)

user1947960
user1947960

Reputation: 298

solved it, needed the following in the .csproj

 <ItemGroup>
    <Content Include="*.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    </Content>
  </ItemGroup>

Upvotes: 6

Related Questions