efcore: Bundle-Migration errors with "cannot access file...being used by another process"
Originally reported by @ryanrichard19 in https://github.com/dotnet/efcore/issues/19693#issuecomment-900396649
For some reason, dotnet publish is behaving differently between Bundle-Migration and dotnet ef migrations bundle.
PM> Bundle-Migration -Verbose
Using project 'MarketingIncentive.Data'.
Using startup project 'MarketingIncentive.API'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.API.deps.json --additionalprobingpath C:\Users\mrrar\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files (x86)\Microsoft\Xamarin\NuGet" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.API.runtimeconfig.json C:\Users\mrrar\.nuget\packages\microsoft.entityframeworkcore.tools\6.0.0-preview.7.21378.4\tools\netcoreapp2.0\any\ef.dll migrations bundle --verbose --no-color --prefix-output --assembly C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll --project C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\MarketingIncentive.Data.csproj --startup-assembly C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.API.dll --startup-project C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj --project-dir C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\ --language C# --working-dir C:\Users\mrrar\Development\MarketingIncentive --root-namespace MarketingIncentive.Data
Using assembly 'MarketingIncentive.Data'.
Using startup assembly 'MarketingIncentive.API'.
Using application base 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0'.
Using working directory 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API'.
Using root namespace 'MarketingIncentive.Data'.
Using project directory 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'MarketingIncentive.API'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'MarketingIncentiveDBContext'.
Finding DbContext classes in the project...
Using context 'MarketingIncentiveDBContext'.
Building bundle...
dotnet publish --output C:\Users\mrrar\AppData\Local\Temp\etc5av4u.vrh\publish
Microsoft (R) Build Engine version 17.0.0-preview-21378-03+d592862ed for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored C:\Users\mrrar\AppData\Local\Temp\etc5av4u.vrh\bundle.csproj (in 319 ms).
2 of 3 projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
MarketingIncentive.Data -> C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 2 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 3 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 4 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 5 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 6 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 7 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 8 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 9 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): warning MSB3026: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Beginning retry 10 in 1000ms. The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): error MSB3027: Could not copy "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". Exceeded retry count of 10. Failed. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Microsoft.Common.CurrentVersion.targets(4685,5): error MSB3021: Unable to copy file "C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.Data\bin\Debug\net6.0\MarketingIncentive.Data.dll" to "bin\Debug\net6.0\MarketingIncentive.Data.dll". The process cannot access the file 'C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\bin\Debug\net6.0\MarketingIncentive.Data.dll' because it is being used by another process. [C:\Users\mrrar\Development\MarketingIncentive\MarketingIncentive.API\MarketingIncentive.API.csproj]
Microsoft.EntityFrameworkCore.Tools.CommandException: Build failed. Use --verbose to see errors.
at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand.Execute(String[] args) in ef.dll:token 0x60001a9+0x23b
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args) in ef.dll:token 0x6000205+0x3b
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) in ef.dll:token 0x6000053+0x100
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) in ef.dll:token 0x60000cf+0x2e
Build failed. Use --verbose to see errors.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 28
- Comments: 73 (8 by maintainers)
I feel that this issue is a show-stopper and not given the proper attention. This makes developers unable to create the bundle, and many will give will up using it completely. Is there any deadline to fix this?
I manged to get it working after a couple of hours using the workaroud
dotnet ef migrations bundle --configuration Bundlebut it is not documented and it seems to not work for everybody.My sistem configuration is: Windows 10, Dotnet sdk 6.0.2. and git bash as terminal.
BTW, have you tried using
--configuration Bundleoption?This is going to require some architectural changes to the way our tools work to fix properly. We hope to address this in 7.0 as part of #26798
I’ve been trying to narrow down if it’s related to post-build/publish events or things like what is running in Program.cs or Startup.cs (web api project). So far nothing makes a difference. So far the only working around I’ve found is setting
--configurationto something that is not debug or release. Heck, evenasdfworks.I’m receiving the same issue on my Azure DevOps pipeline as well as locally.
Updating the command to:
dotnet ef migrations bundle -p MyCoolProject.Infrastructure -s MyCoolProject.Api --verbose --configuration github.com.dotnet.efcore.issues.25555 --forcehas done the trick nicely! : )
with “–configuration github.com.dotnet.efcore.issues.25555” being the workaround and “–force” being in case any local bundles have been created and need to be overwritten.
I gave up, so for me, this is a dead feature. A shame.
This issue is a deal-breaker for me to use the EfCore migrations bundle as part of the CI/CD feature. It must be addressed in upcoming versions.
While I hasn’t been able to reproduce the problem via vs package manager (due to other issues with vs), I was able to reproduce it via
dotnet ef migrations bundle.The main problem is
Microsoft.EntityFrameworkCore.Design.OperationExecutor, which is called fromMicrosoft.EntityFrameworkCore.Tools.Commands.MigrationsBundleCommand. It loads the main assembly viaAssembly.Loadinto dotnet process, so the main file gets locked on windows (most likely this doesn’t happen on linux). Due to that, the childdotnet publishprocess fails, as the lock is taken by the parent process.One way this could have been fixed is by using
AssemblyLoadContextto load and unload the assemblies (after the executor is disposed) atMicrosoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor, but sinceAssemblyLoadContexthas been added with net core 3 (andef toolsis compiled against netcoreapp 2.0)…Same here. Adding dummy
--configurationworked like a charm. So glad I found this thread…Since this issue seems to be affecting everyone (?), should it be mentioned as a known issue in the doc?
Hi there, You can check a solution in this video using the PowerShell: https://www.youtube.com/watch?v=mBxSONeKbPk&t=3s You need to update the EF version in the PowerShell to at least version 6 using the command
I hope that can help you.
Upgrading to 6.0.1 didn’t solve the problem,
This is the only workaround (tested on win 10 & 11):
dotnet ef migrations bundle --configuration Bundle --project ./src/Myproject/Myproject.csproj --verboseImportant: The above workaround doesn’t work when option
—no-buildis set@bricelam maybe the modernization of the EF tools we mentioned at some point would allow us to use the “new” AssemblyLoadcontext to unload…
+1 that the bug exists and +1 that only the workaround seems to help. Closed IDEs, fresh restart - doesn’t help.
@bricelam I recently updated to the latest release of .Net 6 SDK (6.0.100) on Windows 10 Pro. I was NOT getting this error with the 6.0.100-rc.1.21458.32 release.
Note: I have no IDE open, no VS Code or Visual Studio. I’m use only the console and it still gives the error above. Even after a fresh reboot and only the terminal open. So I think it it might be a problem on the dotnet-ef migrations bundle.
I ran into this without VS Code or Visual Studio open at all - simply running from CLI (tried windows terminal - powershell/cmd, and cmd standalone).
However, I found an odd workaround that works but it seems to me that it works because of a bug.
If I execute
dotnet ef migrations bundle --verbose --configuration Debug(or leave--configurationoff, or change toRelease) It executes and fails as described:However, I noticed that if I run the same command with
--configuration Bundleit did this:Note that the publish call doesn’t include the
--configurationflag, but thedotnet builddoes.It seems that if I set
--configurationtoDebugorReleaseit propagates to both thebuildandpublishcalls but if I set it to anything else it gets used for the build but not the publish. I believe this to be a bug (I’d assume config would be passed to both commands always), but because of it that means that the ‘build’ step and ‘publish’ step are using different working directories.I’m on
Edit: I downloaded and installed LockHunter. It DOES say that my dll in the
binfolder is locked bydotnet exec ...which happens as a part of the bundle process.Given severity of the issue (i.e. the feature does NOT work for most of the people) can it be addressed sooner (in v6.0.x)?
I am facing the same issue with
6.0.0-rtm.21519.8. Here is the log -error MSB3021: Unable to copy file "obj\Debug\net6.0\demo2.dll" to "bin\Debug\net6.0\demo2.dll". The process cannot access the file 'C:\demo2\bin\Debug\net6.0\demo2.dll' because it is being used by another process.I don’t have VS Code is running and C# extension is disabled in VS Code.
Note for triage: we should consider the
--disable-build-serversapproach.I’m late to this party but wanted to provide my experience. We are using bundles for pipeline builds (using Azure DevOps) and so far we are not having issues. BUT… locally when testing and debugging I ALWAYS get the “cannot access file…” error. If I immediately re-run the bundle it almost always works the second time. The only thing different from the local run and our pipeline is the use of “–verbose”. I have another powershell script that uses the command without “–verbose” and it has always worked. Maybe the bug is somewhere around this option. Thanks!
It’s not slated for a fix until v7.
Yes, that is what everyone suggests as a workaround… but it does not always work.
That’s the same solution shared above many times but does not always work. It did not for me and just created more errors because making up a fake “configuration” on the CLI can cause its own errors.
I ended up abandoning the bundle option because of this and just went with idempotent script generation, which is much simpler and produces a smaller script file than the large bundle EXE.
Also getting this 😦 Cannot create bundle.
I’m having this problem with EF Core .NET CLI Tools 6.0.2, on Windows, no editor or IDE opened, just trying in Powershell.
Adding --configuration Bundle works. (but feels wrong)
How are people getting past this? I cannot get it to work by creating a dummy configuration name on the command line. When I do that I don’t get any bundle at all because it can’t find the build configuration with the name I made up.
EDIT: I realized that because I am using the
--no-buildoption that this does not work with the workaround mentioned above. (I am using that option because I am testing this in a DevOps pipeline and didn’t need it to re-build the project a second time)So it should be noted that this workaround of making up a fake configuration does not work with the
--no-buildoptionI´m getting this error both with
6.0.0-rc.1.21452.10and6.0.0-rc.2.21480.5it doesn´t matter if restart the machine and just run the bundle script.C:\Program Files\dotnet\sdk\6.0.100-rc.1.21463.6\Microsoft.Common.CurrentVersion.targets(4646,5): warning MSB3026: Could not copy "obj\Debug\net6.0\EFCoreMigrationWeb.dll" to "bin\Debug\net6.0\EFCoreMigrationWeb.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\bin\Debug\net6.0\EFCoreMigrationWeb.dll' because it is being used by another process. [C:\Dev\Delete\EFCoreMigrationPOC\Todo.EFCore\EFCoreMigrationWeb.csproj]Workaround: I downloaded LockHunter and pointed it to the
EFCoreMigrationWeb.dlland when the dotnet process was showing this warning I unlocked the process and it finished creating the bundle.Below is the complete output log. I also uploaded the project to here if you would like to try it out.