dotnet publish fails with --output Cannot create/move a file when that file already exists
See original GitHub issueDescribe the bug
We have an Azure Function solution and we use TeamCity to publish and pack. The publish step is using .NET runner with the following running log: Starting: .NET SDK 6.0.400 “C:\Program Files\dotnet\dotnet.exe” publish “E:\TC\work\fbe36accd285e2ac\Azure Functions\PubAzureFunctions\PubAzureFunctions.sln” --configuration Release --runtime win-x64 --output ./OutputFolder @E:\TC\temp\agentTmp\2.rsp -p:PublishReadyToRun=true --self-contained true
When TeamCity run dotent publish and passing –output it fails 2 times out of 5 with error: “C:\Temp.nuget\packages\microsoft.net.sdk.functions\4.1.2\build\Microsoft.NET.Sdk.Functions.Publish.targets(144,5): error MSB3677: Unable to move file “E:\TC\work\fbe36accd285e2ac\OutputFolder\api-ms-win-crt-time-l1-1-0.dll” to “E:\TC\work\fbe36accd285e2ac\OutputFolder\bin\api-ms-win-crt-time-l1-1-0.dll”. Cannot create a file when that file already exists.”
To Reproduce
When I ran the same command locally I got many warnings of the same issue:
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(254,5): warning MSB3026: Could not copy “C:\Users*.nuget\packages\microsoft.netcore.app.runtime.win-x64\6.0.11\runtimes\win-x64\native\mscorrc.dll" to “D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\mscorrc.dll”. Beginning retry 1 in 1000ms. The process cannot access the file ‘D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\mscorrc.dll’ because it is being used by another process. [D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\ServiceBus\ServiceBus.csproj]
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(254,5): warning MSB3026: Could not copy "C:\Users*.nuget\packages\microsoft.netcore.app.runtime.win-x64\6.0.11\runtimes\win-x64\native\mscordbi.dll” to “D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\mscordbi.dll”. Beginning retry 1 in 1000ms. The process cannot access the file ‘D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\mscordbi.dll’ because it is being used by another process. [D:\Repos
IntegrationPlatform\Azure Functions\PubAzureFunctions\DistributedCache\DistributedCache.csproj]
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(254,5): warning MSB3026: Could not copy “C:\Users*.nuget\packages\microsoft.netcore.app.runtime.win-x64\6.0.11\runtimes\win-x64\native\coreclr.dll" to “D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\coreclr.dll”. Beginning retry 1 in 1000ms. The process cannot access the file ‘D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\coreclr.dll’ because it is being used by another process. [D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\DistributedCache\DistributedCache.csproj]
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(254,5): warning MSB3026: Could not copy "C:\Users*.nuget\packages\microsoft.netcore.app.runtime.win-x64\6.0.11\runtimes\win-x64\native\mscordaccore_amd64_amd64_6.0.1122.52304.dll” to “D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\mscordaccore_amd64_amd64_6.0.1122.52304.dll”. Beginning retry 1 in 1000ms. The process cannot access the file ‘D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\mscordaccore_amd64_amd64_6.0.1122.52304.dll’ because it is being used by another process. [D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\ServiceBus\ServiceBus.csproj]
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(254,5): warning MSB3026: Could not copy “C:\Users*.nuget\packages\microsoft.netcore.app.runtime.win-x64\6.0.11\runtimes\win-x64\native\mscordaccore.dll" to “D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\mscordaccore.dll”. Beginning retry 1 in 1000ms. The process cannot access the file ‘D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\mscordaccore.dll’ because it is being used by another process.
[D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\ServiceBus\ServiceBus.csproj]
C:\Program Files\dotnet\sdk\7.0.100\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(254,5): warning MSB3026: Could not copy "C:\Users*.nuget\packages\microsoft.netcore.app.runtime.win-x64\6.0.11\runtimes\win-x64\lib\net6.0\System.Net.Security.dll” to “D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\System.Net.Security.dll”. Beginning retry 1 in 1000ms. The process cannot access the file ‘D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\OutputFolder\System.Net.Security.dll’ because it is being used by another process. [D:\Repos\IntegrationPlatform\Azure Functions\PubAzureFunctions\DistributedCache\DistributedCache.csproj]
Exceptions (if any)
C:\Temp.nuget\packages\microsoft.net.sdk.functions\4.1.2\build\Microsoft.NET.Sdk.Functions.Publish.targets(144,5): error MSB3677: Unable to move file “E:\TC\work\fbe36accd285e2ac\OutputFolder\api-ms-win-crt-time-l1-1-0.dll” to “E:\TC\work\fbe36accd285e2ac\OutputFolder\bin\api-ms-win-crt-time-l1-1-0.dll”. Cannot create a file when that file already exists.
Further technical details
- Include the output of
dotnet --info
.NET SDK: Version: 7.0.102 Commit: 4bbdd14480
Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.102\
Host: Version: 7.0.2 Architecture: x64 Commit: d037e070eb
.NET SDKs installed: 1.1.14 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.523 [C:\Program Files\dotnet\sdk] 3.1.201 [C:\Program Files\dotnet\sdk] 6.0.400 [C:\Program Files\dotnet\sdk] 7.0.102 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.All 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 1.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.27 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: Not found
Learn more: https://aka.ms/dotnet/info
Download .NET: https://aka.ms/dotnet/download
- The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version
Issue Analytics
- State:
- Created 8 months ago
- Comments:28 (13 by maintainers)
@baronfel has uncovered an issue and working with the azure functions team to see what fixes they need to make. I’m sorry for assuming this was the same issue earlier. I was wrong. That was not the case, and some changes need to be made from the azure functions end most likely. @EngSayed Not your fault you are experiencing this.
I already mentioned many times that I have only 1 application which i am trying to publish. This is very obviously a bug which you guys are ignoring and it makes our life hard.