asp.net core 项目中并没有 web.config ,但每次 dotnet publish 时 .net core cli 都神经病似地复制加了一堆 publish
的奇怪路径下的 web.config 文件,请问如何治疗 .net core 的这个神经病?
/usr/share/dotnet/sdk/3.0.100-preview6-012264/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Publish.targets(149,5): warning MSB3026: Could not copy "/src/Cnblogs.Web/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/web.config" to "/src/Cnblogs.Web/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/web.config". Beginning retry 1 in 1000ms. The process cannot access the file '/src/Cnblogs.Web/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/publish/web.config' because it is being used by another process.
通过一个偏方治好了,在 .csproj 中添加下面的配置 —— 发布时始终排除 web.config 文件
<ItemGroup>
<Content Update="web.config" CopyToPublishDirectory="Never" />
</ItemGroup>
今天通过 Publishing Dotnet Core creates multiples nested directories 这篇博文才知道了问题的真正原因 —— 问题是 publish 目标文件夹不在 bin 文件夹中触发的(我们使用的发布命令是 dotnet publish -c Release -o ./publish
),这样每次发布时都把上次发布的 publish 目标文件夹作为项目的一部分一起发布。
最简单的解决方法就是将 publish 目标文件夹放在 bin 文件夹中。