如何在发布单个 .exe 时发布单独的 appsettings.json 文件?

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

我有一个带有配置文件的控制台应用程序。当我使用 .proj 中的新 PublishSingleFile 设置发布时,它会将应用程序发布为一个文件(好),但它还会将应用程序设置添加到该 .exe.

这意味着此时它并不是一个真正的配置文件,而是一个硬编码值的文件。

如何使用单独的配置文件发布?

当前 .proj 设置

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

已解决,需要在 .csproj

中添加以下内容
 <ItemGroup>
    <Content Include="*.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <ExcludeFromSingleFile>true</ExcludeFromSingleFile>
    </Content>
  </ItemGroup>