将 WebJob 部署到 Azure 时指定的路径、文件名或两者都太长

The specified path, file name, or both are too long when deploying WebJob to Azure

我最近将一个项目升级到 .NET Framework 4.6.1,现在在尝试将其作为 WebJob 部署到 Azure 时遇到问题。我收到以下错误:

C:\Program Files (x86)\Microsoft Visual Studio17\Community\MSBuild\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.targets(2603,5): Error : Copying file C:\Users\XXXXXXXXXXX\Documents\Source\Workspaces\XXXXX Server Application\ServerApplication\XXXXXXXX.IntegrationService\bin\Release\Microsoft.Extensions.DependencyInjection.Abstractions.dll to obj\Release\Package\PackageTmp\app_data\jobs\continuous\XXXXXXXXIntegrationService\Microsoft.Extensions.DependencyInjection.Abstractions.dll failed. The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

我对错误感到困惑,因为路径和文件名加起来只有 189 个字符:

C:\Users\XXXXXXXXXXX\Documents\Source\Workspaces\XXXXX Server Application\ServerApplication\XXXXXXXX.IntegrationService\bin\Release\Microsoft.Extensions.DependencyInjection.Abstractions.dll

如果我从我的项目中删除 Microsoft.Extensions.DependencyInjection.Abstractions.dll,我就可以正常部署了。我试过清理解决方案并重新启动 VS。

I'm confused by the error as the path and filename are only 189 characters combined

那是因为如果错误作为路径和文件名在以下路径中组合只有 189 个字符:

C:\Users\XXXXXXXXXXX...bin\Release\Microsoft.Extensions.DependencyInjection.Abstractions.dll

但是当我们发布项目的时候,VS/MSBuild会把这个文件复制到路径:

obj\Release\Package\PackageTmp\app_data\jobs\continuous\XXXXXXXXIntegrationService\Microsoft.Extensions.DependencyInjection.Abstractions.dll

所以完整的路径和文件名应该是:

C:\Users\XXXXXXXXXXX\Documents\Source\Workspaces\XXXXX Server Application\ServerApplication\XXXXXXXX.IntegrationServiceobj\Release\Package\PackageTmp\app_data\jobs\continuous\XXXXXXXXIntegrationService\Microsoft.Extensions.DependencyInjection.Abstractions.dll

然后路径和文件名加起来大约有 260 个字符,所以 VS/MSBuild 无法访问该路径。要解决此问题,您可以尝试将 solutions/projects 移动到根目录,例如:C:\Workspaces