ASP.Net Core 发布失败,原因是无法复制该文件。

6

我正在尝试将一个 WebJob 发布到 Azure 上,但是我遇到了如下的一些错误。看起来是因为在“Out”后面的路径中它添加了两个反斜杠而不是一个(PubTmp\Out\\app_data)。

28>Could not copy "C:\Development\TNG\ActivationService\bin\Release\netcoreapp3.1\TNG.Services.WindowsService.ActivationService.runtimeconfig.json" to "C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\TNG.Services.WindowsService.ActivationService.runtimeconfig.json". Beginning retry 1 in 1000ms. Could not find a part of the path 'C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\TNG.Services.WindowsService.ActivationService.runtimeconfig.json'. 
28>Could not copy "C:\Users\mohsen.rezaei\.nuget\packages\microsoft.extensions.configuration.azureappconfiguration\4.0.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.AzureAppConfiguration.dll" to "C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.Configuration.AzureAppConfiguration.dll". Beginning retry 1 in 1000ms. Could not find a part of the path 'C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.Configuration.AzureAppConfiguration.dll'. 
28>Could not copy "C:\Users\mohsen.rezaei\.nuget\packages\microsoft.extensions.configuration.environmentvariables\3.1.6\lib\netcoreapp3.1\Microsoft.Extensions.Configuration.EnvironmentVariables.dll" to "C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.Configuration.EnvironmentVariables.dll". Beginning retry 1 in 1000ms. Could not find a part of the path 'C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.Configuration.EnvironmentVariables.dll'. 
28>Could not copy "C:\Users\mohsen.rezaei\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\3.1.6\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll" to "C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.DependencyInjection.Abstractions.dll". Beginning retry 1 in 1000ms. Could not find a part of the path 'C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.DependencyInjection.Abstractions.dll'. 
28>Could not copy "C:\Users\mohsen.rezaei\.nuget\packages\microsoft.extensions.options.configurationextensions\3.1.6\lib\netcoreapp3.1\Microsoft.Extensions.Options.ConfigurationExtensions.dll" to "C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.Options.ConfigurationExtensions.dll". Beginning retry 1 in 1000ms. Could not find a part of the path 'C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.Options.ConfigurationExtensions.dll'. 
28>Could not copy "C:\Users\mohsen.rezaei\.nuget\packages\system.data.sqlclient\4.8.1\runtimes\unix\lib\netcoreapp2.1\System.Data.SqlClient.dll" to "C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\runtimes\unix\lib\netcoreapp2.1\System.Data.SqlClient.dll". Beginning retry 1 in 1000ms. Could not find a part of the path 'C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\runtimes\unix\lib\netcoreapp2.1\System.Data.SqlClient.dll'. 
28>Could not copy "C:\Development\TNG\ActivationService\bin\Release\netcoreapp3.1\TNG.Services.WindowsService.ActivationService.runtimeconfig.json" to "C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\TNG.Services.WindowsService.ActivationService.runtimeconfig.json". Beginning retry 2 in 1000ms. Could not find a part of the path 'C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\TNG.Services.WindowsService.ActivationService.runtimeconfig.json'. 
28>Could not copy "C:\Users\mohsen.rezaei\.nuget\packages\microsoft.extensions.configuration.azureappconfiguration\4.0.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.AzureAppConfiguration.dll" to "C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.Configuration.AzureAppConfiguration.dll". Beginning retry 2 in 1000ms. Could not find a part of the path 'C:\Development\TNG\ActivationService\obj\Release\netcoreapp3.1\PubTmp\Out\\app_data\Jobs\Continuous\TNG.Services.WindowsService.ActivationService\Microsoft.Extensions.Configuration.AzureAppConfiguration.dll'. 
Further technical details

我正在使用ASP.Net Core 3.1和Visual Studio 2019。


在我的情况下,问题是项目路径太长了。似乎有一个256个字符的限制。它可以使用“Debug”配置文件,但不能使用“Release”配置文件,因此我将项目路径缩短到256个字符以下,现在它可以工作了。 - Popa Andrei
3个回答

6
可能是发布路径太长了。
以下是我所做的步骤:
  1. 重命名您的项目(使其更短)。
  2. 如果其他项目引用了您重命名的项目,请修复它们的依赖项。
  3. 重命名包含项目的文件夹。
  4. 从解决方案中删除项目,然后再添加它(也可修复引用问题)。
  5. 删除发布配置文件。
  6. 清理并重新构建。
  7. 创建一个新的发布配置文件。
如果这不起作用,可能是路径仍然太长。
祝好运。

0

你可能只需要下载文件并使用第三方程序上传它。如果你从代码中下载文件,请确保在代码开头放置以下代码。希望这能起作用!

<javascript-void0>

0

我遇到了同样的问题,一切都正常工作,但在尝试从Visual Studio发布WebJob时,没有更改任何内容,我仍然收到相同的错误。

我通过将目标框架更改为.Net 5.0而不是Net Core 3.1来解决了这个问题。

以下是我用来解决问题的步骤:

  1. 右键单击项目,然后在目标框架下拉菜单中选择.NET 5.0。
  2. 清理项目
  3. 关闭Visual Studio
  4. 手动删除obj和bin文件夹
  5. 打开Visual Studio
  6. 右键单击项目,然后选择重新生成

当所有内容成功编译时,请再次尝试发布-它应该可以工作。

如果您的依赖项尚未与.NET 5.0兼容,我建议您降级到net core 2.0(按照上述步骤)然后再将其更改回net core 3.1(按照上述步骤)。

我不知道为什么会发生这种情况,但至少对我有效。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接