question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet publish fails with --output Cannot create/move a file when that file already exists

See original GitHub issue

Describe 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:open
  • Created 8 months ago
  • Comments:28 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
nagilsoncommented, Aug 16, 2023

@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.

1reaction
EngSayedcommented, Apr 7, 2023

The status is the same as what @baronfel mentioned earlier. We suggest you publish each project individually. As for @EngSayed’s comment: It can be a single application, but based on your output you’re still publishing a solution. I assume the solution has more than one project. If there is more than one project and you point to 1 flat output folder, then the artifacts and .dlls can conflict with one another while they publish/build/etc in parallel. It may be down the pipeline to fix this eventually but it will require significant amounts of code to be re-written.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Cannot create a file when that file already exists when ...
I am getting "Cannot create a file when that file already exists" error. Below is my code. could any one suggest on this?...
Read more >
Generate error for duplicate files in publish output - .NET
NET SDK generates an error when files from different source paths would be copied to the same location in the publish output.
Read more >
Resolved - Publish failed. Check output for more details.
Just set the target framework with a click of a button in the publish area, and you are good.
Read more >
Cannot Create a File When That File Already Exists ... - YouTube
Cannot Create a File When That File Already Exists In Windows 10/8/7 FIX ... The issue is reported to occur with multiple Windows...
Read more >
https://raw.githubusercontent.com/tennc/webshell/m...
You can copy, create, move and delete files. Text files can be edited and groups of files and folders can be downloaded as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found