Visual studio hangs when building ordinary c# projects/files are locked afterwards

Planck, Jeremy 1 Reputation point
2023-07-20T11:58:40.59+00:00

Using Microsoft Visual Studio Professional 2019, Version 16.11.27

Building ordinary c# solutions/projects (happens intermittently on all our projects), sometimes the build will hang forever. This seems to be due to some lock on the file - once this condition has occurred, we will usually find there is one file in the output directory that can no longer be renamed, moved, deleted, etc. The lock remains until the computer is restarted. Ending the visual studio process and restarting VS does not fix the issue, so when this is happening we are often having to restart our computers every other build or so.

We have tried using task manager/resource monitor, process explorer, process monitor, etc. to look for something still using the file, but none of the tools show anything happening to the files that are locked. Yet still building with VS will always fail and the files cannot be used until the computer is restarted, which will guarantee one successful build but then afterwards it depends on whether the file was locked or not.

This issue started about 3 months ago, though there are a lot of updates (at least one a month, usually two or three) and I'm not sure they were applied at the time of MS releasing them so that might not be super helpful.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,407 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anna Xiu-MSFT 30,816 Reputation points Microsoft Vendor
    2023-07-21T07:01:47.53+00:00

    Hi @Planck, Jeremy

    Welcome to Microsoft Q&A! 

    It may be caused by the installed extensions, please temporarily disable or uninstall the installed extensions under Extensions > Manage Extensions > Installed.  

    Meanwhile, please turn off the anti-virus software on your pc. 

    Then, close all running VS instances and manually delete the .vsbin and obj folders in the project folder.

    You can run VS2019 as administrator and rebuild the solution. 

    Sincerely,

    Anna


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.