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



我有一个带有配置文件的控制台应用程序。当我使用 .proj 中的新发布单个文件设置发布时,它会将应用程序发布为一个文件(好),但它也会将应用程序设置添加到该.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>

最新更新