Repository navigation
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I'm running https://github.com/dotnet/eShopSupport from VS, launching using Ctrl+F5. I understand that when subsequently building a referenced project (e.g., the Backend project in that solution), VS is supposed to shut down and restart that one project while leaving AppHost running (citation).
However, the vast majority of the time, this does not work for me, and building a referenced project fails with errors like:
1>C:\Program Files\Microsoft Visual Studio\2022\IntPreview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5321,5): warning MSB3026: Could not copy "D:\git\dotnet\eShopSupport\src\Backend\obj\Debug\net8.0\apphost.exe" to "bin\Debug\net8.0\Backend.exe". Beginning retry 1 in 1000ms. The process cannot access the file 'bin\Debug\net8.0\Backend.exe' because it is being used by another process. The file is locked by: "Backend (2592)"
1>C:\Program Files\Microsoft Visual Studio\2022\IntPreview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5321,5): warning MSB3026: Could not copy "D:\git\dotnet\eShopSupport\src\Backend\obj\Debug\net8.0\apphost.exe" to "bin\Debug\net8.0\Backend.exe". Beginning retry 2 in 1000ms. The process cannot access the file 'bin\Debug\net8.0\Backend.exe' because it is being used by another process. The file is locked by: "Backend (2592)"
1>C:\Program Files\Microsoft Visual Studio\2022\IntPreview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5321,5): warning MSB3026: Could not copy "D:\git\dotnet\eShopSupport\src\Backend\obj\Debug\net8.0\apphost.exe" to "bin\Debug\net8.0\Backend.exe". Beginning retry 3 in 1000ms. The process cannot access the file 'bin\Debug\net8.0\Backend.exe' because it is being used by another process. The file is locked by: "Backend (2592)"
1>C:\Program Files\Microsoft Visual Studio\2022\IntPreview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(5321,5): warning MSB3026: Could not copy "D:\git\dotnet\eShopSupport\src\Backend\obj\Debug\net8.0\apphost.exe" to "bin\Debug\net8.0\Backend.exe". Beginning retry 4 in 1000ms. The process cannot access the file 'bin\Debug\net8.0\Backend.exe' because it is being used by another process. The file is locked by: "Backend (2592)"
etc.
I've tried VS versions:
- Version 17.11.0 Preview 4.0
- Version 17.12.0 Preview 1.0 [35117.301.main]
and have disabled every VS extension I can, and disabled hot reload, but the same issue remains.
This is the most impactful issue on productivity when working on this project, as there's no choice but to manually kill and restart AppHost for literally every code change, which in turn means restarting some large Docker containers including Ollama.
I don't think it's specifically a problem in the app code, because it sometimes works. If I restart VS often enough and keep deleting the .vs directory, then occasionally it can rebuild the referenced projects without the file being locked. But this is a short-lived victory as the locking problem soon comes back and is present the vast majority of the time.
Expected Behavior
VS should be able to rebuild referenced projects without failing due to the .exe or .dll files being locked.
Steps To Reproduce
- Clone and run https://github.com/dotnet/eShopSupport (via Ctrl+F5 in VS)
- Visit
StaffWebUIand observe it working - Make any edit (e.g., whitespace) in
src/Backend/Program.csand try to build that one project - Expected: builds that one project while leaving AppHost running
- Actual: fails with the "file locked" error mentioned above
Exceptions (if any)
No response
.NET Version info
.NET SDK:
Version: 8.0.400-preview.0.24324.5
Commit: 736a2616db
Workload version: 8.0.400-manifests.7ccdde63
MSBuild version: 17.11.0+1192b22fd
Runtime Environment:
OS Name: Windows
OS Version: 10.0.22631
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\8.0.400-preview.0.24324.5\
.NET workloads installed:
Configured to use loose manifests when installing new manifests.
[aspire]
Installation Source: SDK 8.0.400-preview.0, VS 17.11.35111.106, VS 17.12.35117.301
Manifest Version: 8.0.2/8.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.0.2\WorkloadManifest.json
Install Type: Msi
Host:
Version: 8.0.7
Architecture: x64
Commit: 2aade6beb0
.NET SDKs installed:
7.0.120 [C:\Program Files\dotnet\sdk]
8.0.107 [C:\Program Files\dotnet\sdk]
8.0.400-preview.0.24324.5 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Anything else?
Aspire packages are all 8.0.2
Activity
davidfowl commentedon Sep 8, 2024
Vijay Ramakrishnan (@vijayrkn) I put this in 9.0. We should look at it.
BillHiebert commentedon Sep 26, 2024
David Fowler (@davidfowl) , Steve Sanderson (@SteveSandersonMS) so far I have not been able to reproduce this. When looking more closely at the code I discovered that VS is not handling replicas properly. It was only stopping and restarting the first one. I have a PR out with a fix for that, but this project does not use replicas so something else must be going on. From the VS side the code is very straight forward and it is difficult to see a case where it would not stop the process - unless the call to stop the process failed.
SteveSandersonMS commentedon Oct 25, 2024
This bug occurred several times during my .NET@MS presentation yesterday - check the recording if you'd like to see! (Not sure when/where that becomes available). I was forced to restart the app completely a few times, which takes quite a while and certainly interfered with demo flow. This was on Aspire 9.
davidfowl commentedon Oct 25, 2024
How did you trigger the rebuild in VS?
SteveSandersonMS commentedon Oct 25, 2024
Just pressing ctrl+b
Sjark commentedon Aug 27, 2025
This also happens when using dotnet run to run the app host.
I start the apphost using:
dotnet run --project $appHostProjectPath --launch-profile httpIf I then try to build a spesific project, it fails with
The process cannot access the file '<filepath>' because it is being used by another processWorkaround for now it to go to the aspire dashboard, stop the spesific service, do a build and start it again.
I have also tried the
no-buildflag on dotnet run, but still the same issuedavidfowl commentedon Aug 27, 2025
When you use dotnet run it's expected. When you use visual studio or vs code now and rebuild a specific project, it will restart that project without intervention.
Sjark commentedon Aug 27, 2025
Just tested by running in VS Code, and it worked as expected when rebuilding a spesific project.
Is there any plans to supporting this when running using dotnet run or multiple vs code instances?
Our aspire project consist of multiple git repos/dotnet solutions. We have one "aspire" solution that has references to all the other .net projects, but we normally just open the one service we are going to work on in it's own vs code window.
davidfowl commentedon Aug 27, 2025
aspire run and dotnet watch
Not sure what you mean here
Sjark commentedon Aug 27, 2025
Ok, I'll try aspire run. What I mean with multiple vs code instances is that we open each service/git repo in it's own vs code window, so I have one window VS Code window that has the Aspire App Host project, and a separate VS Code window that has the code for one of the services running in Aspire, so even if I run the app host in VS Code, when I try to re-build the service from the other VS Code window, I get the locking issue.
davidfowl commentedon Aug 28, 2025
Yea those multiple instances don’t know about each other so they’ll fight. That’s not really fixable without some outer building orchestrator.
cc Chet Husk (@baronfel) for ideas
Sjark commentedon Sep 1, 2025
It would be really nice if it worked in multi-repo scenarios. Workaround for now is to create a custom command that stops the service, runs dotnet build and starts the service again. This works fine, but would be really nice to just hit build in vs code.
davidfowl commentedon Sep 1, 2025
The solution for that is to create a solution so that VS knows about all of the projects and can properly coordinate builds… OR build elsewhere.