2

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>
TylerH
  • 20,799
  • 66
  • 75
  • 101
user1947960
  • 278
  • 2
  • 10
  • You can have appsettings that target specific environments - like Development, Production etc -is that your question? But this is in the .NetCore environment though. – Rakesh Oct 22 '19 at 14:47
  • I keep the original version in the parent folder, then I take it to the proper folder every publication. On Windows I noticed you could refer the parent folder, but it does not work on Linux. – Mario Vernari Oct 22 '19 at 14:48
  • @Rakesh no sorry, I mean when I publish using dotnet publish I get the .exe but the appsettings.json is inside the exe not alongside it, so it can't be edited. – user1947960 Oct 22 '19 at 14:52

1 Answers1

5

solved it, needed the following in the .csproj

 <ItemGroup>
    <Content Include="*.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    </Content>
  </ItemGroup>
user1947960
  • 278
  • 2
  • 10