使用命令發布
dotnet restore
dotnet publish -c Release -r win-x64 -o "D:\services"
這樣發布總是是將配置文件覆蓋
這時候打開項目.csproj新增配置文件
<ItemGroup> <Content Update="appsettings.json" CopyToPublishDirectory="Never" Condition="'$(Configuration)' == 'Release'"/> </ItemGroup>
CopyToPublishDirectory 的值
Never 從不復制
PreserveNewest 復制最新的
Always 總是復制
我這里設置條件只有為Release環境才不復制配置文件 目的是不影響調試