【问题标题】:Failed to copy file when trying to publish in Visual Studio (2019)尝试在 Visual Studio (2019) 中发布时复制文件失败
【发布时间】:2026-01-29 19:50:01
【问题描述】:

我正在尝试根据 Microsoft's own guide 发布 C# 项目,但是当我尝试这样做时遇到以下错误(当构建输出日志级别设置为诊断时)。

Error: Failed to copy file '[path that is over 260 characters]' to '[path that is under 260 characters]'.
Unable to add '[path that is under 260 characters]' to the Web site.
Unable to add file '[subset of path that is under 260 characters]'.
The system cannot find the path specified.

我已经抽象了字面路径以使错误更易于阅读。

这里发生了什么?

【问题讨论】:

    标签: c# visual-studio publishing


    【解决方案1】:

    Enabling Windows Long Paths(路径超过 260 个字符)和重新启动将不会将您保存在这里。

    如果您遇到此问题,那么一种解决方案是移动您的项目,使其尝试复制的路径不超过 260 个字符。从本质上讲,将您的项目移动到尽可能靠近驱动器根的位置。

    可能有更好的解决方案,但是我一直无法找到一种方法来通知 Microsoft 的发布工具正确解释超过 260 的路径。

    【讨论】: