dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.66k stars 1.06k forks source link

Publish failed due to Unable to copy file #14994

Open mohsenrezaeis opened 3 years ago

mohsenrezaeis commented 3 years ago

Describe the bug

i'm trying to publish a webjob to Azure but I get some errors like the following. looks like it's because in the path after 'Out' it adds two backslashes instead of one (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

I'm using ASP.Net Core 3.1 and visual studio 2019

javiercn commented 3 years ago

@mohsenrezaeis thanks for contacting us.

@vijayrkn is this the web tools?

vijayrkn commented 3 years ago

Depends. Is this a .net core web job or a full framework web job? Can you please share the csproj?

mohsenrezaeis commented 3 years ago

it's a .Net Core project. Here is the project file.

<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UserSecretsId>essdev</UserSecretsId>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="..\..\CoreService\TNG.Services.CoreService.Contract.Web\appsettings.json" Link="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Identity" Version="1.2.3" />
    <PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="3.1.0" />
    <PackageReference Include="Topshelf.autofac" Version="4.0.1" />
    <PackageReference Include="Topshelf.Nlog" Version="4.2.1" />
    <PackageReference Include="Mongodb.driver" Version="2.10.4" />
    <PackageReference Include="Mongodb.messaging" Version="2.0.0.28" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.6" />
    <PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="3.1.6" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="3.1.6" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.6" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="3.1.6" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.6" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\..\TNG.Core\TNG.Core.MongoQueue\TNG.Core.MongoQueue.csproj" />
    <ProjectReference Include="..\..\..\TNG.Core\TNG.Core\TNG.Core.csproj" />
    <ProjectReference Include="..\TNG.Services.Activation.Core\TNG.Services.Activation.Core.csproj" />
    <ProjectReference Include="..\TNG.Services.Activation.Domain\TNG.Services.Activation.Domain.csproj" />
    <ProjectReference Include="..\TNG.Services.Activation.Logic\TNG.Services.Activation.Logic.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="Settings.job">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
</Project>
Pilchie commented 3 years ago

Ping @vijayrkn ?

vijayrkn commented 3 years ago

This belongs to the dotnet/sdk repo. Can you please move there?

jerry-santana commented 3 years ago

Same issue here, net core 3.1 and vs 2019. Any workaround?

mp-pellsoftware commented 3 years ago

We are experiencing the same issue on multiple machines. When we clone our solution to an external drive we see this error, when we clone it to our "C:" (the drive with Windows/Visual Studio) installed we do not see the error. Seems as though we can copy the solution folder from C to any other drive as well and that also works.

Cloning the same exact repo/solution to external drive produces the "could not copy" while cloning to C: (Windows/VS) does not.

JiriRichter commented 3 years ago

I juts hit the same issue publishing a Asp.Net Core 3.1 web job from VS. It appears it is related to the length of the target path when copying file to the TempPub folder. It seems that when the path exceeds 256 characters it will cause the publish error. I was able to resolve the issue by simply shortening the name of assemblies and/or the web job name.

sebastianzolg commented 3 years ago

@JiriRichter That did the trick! Thanks for letting us know.

dbeavon commented 3 years ago

Any plans to fix this? Shortening names isn't always as easy as it should be.

A good chunk of the path is outside of my control: obj\Debug\net471\win7-x86\PubTmp\Out\app_data\Jobs\Continuous

Seems like there should be a checkbox to do deployments via the user's temp directory rather that using these massively nested folders.

I was able to work around the problem by creating a file share and mapping it as a drive, and opening that mapped drive whenever working on my webjob project. But it would be nice if someone could prioritize and fix this issue. I also considered playing with the LongPathsEnabled registry key on Windows 10 but that doesn't seem like a sure thing either.

donghexu commented 3 years ago

What is the update of this issue? It's been 9 months...

joeloff commented 3 years ago

There is an PublishIntermediateTempPath property. Can you try setting that. It's only used for web and things like Azure web jobs (which it sounds like you are using)? The property is public and supports being overridden

kylemcnee commented 2 years ago

I've been blocked by this for six months, it's complaining about bootstrap files and i think it's because of a character limit. There's nothing I can do to shorten the path lower than 256 characters.

kylemcnee commented 2 years ago

This has been blocking my work for over a year at this point. If you're reading this, be warned! Do anything you possibly can to avoid working with .NET

Stricnis commented 2 years ago

@kylemcnee I had the same issue but fixed it thanks to @joeloff comment. You can add these 2 lines to your publish profile to use different (shorter) paths during the publish: <PublishIntermediateTempPath>D:\Temp\VS2019\MyWebJob\Tmp\</PublishIntermediateTempPath> <PublishIntermediateOutputPath>D:\Temp\VS2019\MyWebJob\Out\</PublishIntermediateOutputPath> Hope this helps.

micahtan commented 2 years ago

The PublishIntermediateTempPath workaround works well, but ran into a problem where this excludes the Settings.job file on publish. When the project folder is truncated to not need PublishIntermediateTempPath the Settings.job file is included in the publish output.

royhazan commented 1 year ago

I went into the publish profile ({project folder}\Properties\PublishProfiles\ClickOnceProfile.pubxml), and changed the following 2 entries as follows:

publish\Release\
<PublishUrl>publish\Release</PublishUrl>

Then the project publishes to: publish\Release