Visual Studio hangs constantly during build

Visual StudioVisual Studio-2012BuildMsbuildDeadlock

Visual Studio Problem Overview


Probably between 25 and 50% of the times I build my solution, I see this:

"The operation you requested is taking longer than expected to complete. This dialog will close when the action completes."

I hate this window in ways I can't describe. It never resolves, the Cancel button is never enabled, and the only way to remedy it is to kill the devenv process and load up my entire solution again, knowing full well that I've fixed nothing and I'm equally liable to see the same thing when I attempt my build.

My solution is about 60 projects in total, which are mostly C# class libraries, with a few each of web applications, web services, and console applications. However, the problem persists even when building one slice of the codebase with the majority (50) of the projects unloaded.

My problem is that the output windows doesn't tell me anything at the point at which it freezes, and I don't know how else to determine the cause of this lockup. If I were to guess, I would assume that it's a deadlock in the filesystem or something, but I don't know how to go about proving this--much less how to prevent it.

What can I do to diagnose and eliminate this from my solution so that I never see it again? In general, how can I diagnose problems that occur during a build?

Visual Studio Solutions


Solution 1 - Visual Studio

Had a similar issue, VS would hang for 45 or so seconds then build for 4 seconds and complete. The 45 seconds of hang would not produce any output to GUI and VS would hang.

Using ProcMon I could see 3 million+ file operations on the /packages/ folder via devenv.exe when I would build this project (and would continue for some time after)!! The first steps of the build you can see that it was checking EVERY PACKAGE to see if it needed to do a package restore (it did not).

Since I tend to blame NuGet for everything, I disabled NuGet Package Restore "allow NuGet to download missing packages" checkbox under Visual Studio -> Options -> Nuget Package Manager -> General. To my delight, the build was very fast. 5 seconds total!

Turns out that we had enable package restore on build enabled (I think this is on by default now in VS) AND we also had the packages checked into source control. It seems this causes TFS to thrash in some way... Checking for restoring packages must trigger TFS to do some source control operation checks.

FYI this was VS2013 UPDATE 4 - Nuget version: 2.8.50926.663, on a sln with NumberOfProjects = 38, but I could recreate this hang just building a single csproj with 2 dependencies.

Update:

Localhost "Rebuild All" on Sln with SccNumberOfProjects = 53 was taking 7:05 with 2 minutes of visual studio frozen / unresponsive

  • down to 4:14 on a 2 core i5 with no freezing
  • down to 2:44 on a 4 core i7

Also: This was on a machine with various file watcher security tools, likely not adding any speed to this whole process... and possibly to blame.

Update in 2021: If you are looking for a paradigm shift, the new SDK style csproj format (see migration tool) + nuget PackageReference makes updates almost instant (< 20 SECONDS for same projects in scenarios above) - highly recommend you upgrade any legacy projects. ** Known incompatibility - website package references do not support static file references via nuget ( checkout LibMan)

Solution 2 - Visual Studio

I have seen this happen on large projects when MSBuild is running with the diagnostic switch turned on. In Visual Studio, go to Tools / Options / Projects & Solutions / Build And Run, then check the MSBuild project build output verbosity value. If its not set to Minimal, try setting to minimal and see if your builds are able to complete.

Solution 3 - Visual Studio

In my case setting "maximum number of parallel project builds" to 1 kinda helped (i.e. building a project from clean state causes 1 min freeze followed by normal build and every subsequent build works fine).

Aforementioned setting can be set in Tool -> Options -> Projects and Solutions -> Build and Run.

Solution 4 - Visual Studio

Seems like running Visual Studio as Administrator solved the problem for me! (For always running a program as Administrator see https://stackoverflow.com/questions/9654833/how-to-run-visual-studio-as-administrator-by-default)

Solution 5 - Visual Studio

I did not try any of the above solution as by the time I tried my approach - all was well again.

My steps are as following:

  1. Close VS
  2. Delete the .vs folder
  3. Open my solution
  4. Clean Solution OK
  5. Build Solution OK
  6. Optional Rebuild OK

Solution 6 - Visual Studio

I've found Visual Studio hanging a lot on building larger projects. Turns out it was ReSharper. After I turned it off: Tools -> Options -> ReSharper -> Suspend Now, everything built fine no issues (even on very large solutions, 100+ projects)

Solution 7 - Visual Studio

There was a suggestion on Microsoft Connect that Modelling project was responsible for the freezes. I removed a Modelling project from our solution and have experienced no freeze since then (about a week).

Solution 8 - Visual Studio

VS2019 exhibits this issue as well for me, in my case, the problem was because of dependencies stored on a network share. I have a hunch that Windows Defender Antivirus was scanning a lot of extra stuff that was in the network share, which is only accessible when connected to a fairly slow VPN.

Solution 9 - Visual Studio

For me the issue was witch an extension that automatically runs T4 templates on build (AutoT4). Disabling it when working with solutions with EF fixed the issue.

Solution 10 - Visual Studio

I moved my VS 2008 development platform from Windows 7 to Windows 10 and encountered a situation where Visual Studio would hang up every time I tried to build a large project. I had to build the project, then use the Task Manager to kill VS and then restart. Needless to say, this made debugging really difficult! Anyhow, the problem was that in moving to Win 10, VS was no longer running as administrator (and perhaps Win 10 is more particular about privileges). Changing the properties so that the program ran as administrator resolved the problem. (IngoB -- I don't have enough status to comment on your post, but thanks for pointing this out!)

Solution 11 - Visual Studio

Just try below command with admin mode. Before running this command make sure to close all VS instance.

devenv /resetuserdata

Note: devenv is located at C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE

Solution 12 - Visual Studio

In addition to the felickz's answer which solves (or almost solves) this problem for builds:

Except the problem during a build I also had problem with the Package Management Console. It took about a minute to wait for it. Using the procmon I found that the NuGet repository folder was parsed each time this window is opened (very smart, Microsoft!). There were about 1000 packages in this folder. After removing everything from the above folder the performance problem diapered.

Note that my answer relates to the VS 2015 (and may be below). I didn't tested, but suspect in VS 2017 it should be ok.

Solution 13 - Visual Studio

For me it was something to do with npm package install that ran automatically. I went to Tools > Options > Project and Solutions > External Web Tools and unchecked all external tools and restarted VS. After that, I was able to build it again. I know I need them to be checked but I need to figure out what's triggering them and what's wrong with this solution file.

Solution 14 - Visual Studio

Visual Studio 2017

Removing Anaconda3 from the installation fixed it. In procmon I saw hundreds of thousands of calls looking for files in the Anaconda3 folder from hundreds of instances of powershell spawned by msbuild.

Solution 15 - Visual Studio

I had this problem because of an issue restoring nuget packages. There was a duplicate entry in the packages.config file. Rather than report it as an error, the build would just hang forever.

I didn't discover the problem until I tried to restore the nuget package through the "Manage Nuget Packages..." option in the menu. After removing the duplicate, the build completes properly.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbwerksView Question on Stackoverflow
Solution 1 - Visual StudiofelickzView Answer on Stackoverflow
Solution 2 - Visual StudioPat PView Answer on Stackoverflow
Solution 3 - Visual StudioTomasz MaczyńskiView Answer on Stackoverflow
Solution 4 - Visual StudioIngoBView Answer on Stackoverflow
Solution 5 - Visual StudioAlex LeoView Answer on Stackoverflow
Solution 6 - Visual Studiot_warsopView Answer on Stackoverflow
Solution 7 - Visual Studiost-devView Answer on Stackoverflow
Solution 8 - Visual StudioK0D4View Answer on Stackoverflow
Solution 9 - Visual StudioDavid CholtView Answer on Stackoverflow
Solution 10 - Visual StudioRobert CodyView Answer on Stackoverflow
Solution 11 - Visual StudioJayesh VaghasiyaView Answer on Stackoverflow
Solution 12 - Visual StudioKamareyView Answer on Stackoverflow
Solution 13 - Visual StudioPersyJackView Answer on Stackoverflow
Solution 14 - Visual StudioThe Sharp NinjaView Answer on Stackoverflow
Solution 15 - Visual StudiokomodospView Answer on Stackoverflow