82

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?

bwerks
  • 8,651
  • 14
  • 68
  • 100
  • 1
    possible duplicate of [What is this 'Waiting for Background operation' in Visual Studio 2012?](http://stackoverflow.com/questions/12175784/what-is-this-waiting-for-background-operation-in-visual-studio-2012) – Hans Passant Sep 26 '13 at 00:52
  • I added clarification to specify that my problem is seen specifically during build, rather than during unrelated coding as suggested by the linked question. – bwerks Sep 27 '13 at 23:41
  • 1
    I am suffering with the EXACT same problem... I wonder if you had ever found out what the issue was – overloading Nov 08 '13 at 19:32
  • Nope. All I know is that VS 2013 seems to have quietly fixed the problem, so this is another reason to abandon 2012 entirely. – bwerks Nov 10 '13 at 23:38
  • No it haven't. For larger solutions (no matter of what kind) VS 2013 consistently hangs during builds... – Paul Michalik Dec 03 '13 at 14:16
  • ...At least this is the case on the Win7 box I am sitting in front of right now... – Paul Michalik Dec 03 '13 at 14:23
  • Interesting. My particular solution (now only a little less than 100 projects) hasn't experienced this in 2013 yet. Sounds even more squirrelly now. – bwerks Dec 04 '13 at 17:13
  • I am experiencing this still in VS2017 which is a real shame. I am able to click the Cancel Build button (as in, it's not disabled as in OP's scenario), but it does nothing, so I too must force-kill VS via Task Manger. I'm thinking it may be that my hard drive is starting to go bad, but disk checks report nothing faulty. I'm quite lost on how to fix this. – Chad Jan 25 '20 at 18:47

16 Answers16

70

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)

felickz
  • 4,292
  • 3
  • 33
  • 37
  • 2
    Didn't work for me. Still 20 seconds of invisible churn to do a 1 second build. – JohnOpincar Aug 05 '15 at 14:14
  • 1
    @JohnOpincar I would suggest using procmon to check if you are getting a high amount of disk activity or access issues that maybe will help understand what is slowing you down – felickz Aug 24 '15 at 03:01
  • 1
    For clarification, "EVERY PACKAGE" here means *every* single package file you have in `$(SolutionDir)\packages\`, even if you aren't using them (e.g. the tons of old versions I had were still being read!). I think @felickz is quite right in blaming NuGet for everything. Note that turning the option off in VS2015 will not apply if you have a .nugets solution folder from older versions of VS (so many reasons to hate NuGet). – makhdumi Jan 08 '16 at 17:49
  • Could you please specify the path to the Nuget option for VS2012? Because I somehow miss it in the Tools menu. – Anton Papin May 10 '16 at 12:38
  • @AntonPapin try [here](https://www.bing.com/images/search?q=visual+studio+2012+Nuget+Package+Restore&view=detailv2&&id=141446108A736233C8E54965E6F601CBA097BE7A&selectedIndex=14&ccid=g9SPsHZK&simid=608015014741803296&thid=OIP.M83d48fb0764a197d8916186046f45e08o0&ajaxhist=0) – felickz May 18 '16 at 17:48
  • 2
    This resolved build hangs for me with VS2015 as well. – Chris Gillum Sep 03 '16 at 01:06
  • We generally avoid adding packages folder to TFS. If added, we leave it there for emergency GETs and Cloak it by default, so that it is disconnected from the local folder – Sara Oct 14 '16 at 06:17
  • @sapbucket love you too :) ... and most of all you should love [sys internals process monitor tool](https://technet.microsoft.com/en-US/sysinternals/processmonitor.aspx) :) – felickz Jan 02 '17 at 21:16
  • This has resolved VS2019 hangs for me. Build times had slowed to a crawl since I had turned this setting on. But I never realized this was the cause. Now I got my 5 second build & run times back again. Thanks! – Jay Dec 28 '20 at 14:49
47

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.

Pat P
  • 651
  • 6
  • 4
23

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
Alex Leo
  • 2,781
  • 2
  • 13
  • 29
12

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.

Tomasz Maczyński
  • 973
  • 10
  • 24
11

Seems like running Visual Studio as Administrator solved the problem for me! (For always running a program as Administrator see How to Run Visual Studio as Administrator by default)

IngoB
  • 2,552
  • 1
  • 20
  • 35
6

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)

t_warsop
  • 1,170
  • 2
  • 24
  • 38
3

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

st-dev
  • 41
  • 4
  • My modeling projects actually fail my build constantly in 2012, but in those cases with explicit errors citing something related to dgml files. I wouldn't be at all surprised to learn that general flakiness in Modeling project MSBuild was to blame for these other symptoms too. – bwerks Feb 05 '14 at 18:43
  • This was the answer for me. Our primary solution has about 25 projects along with the dreaded Modelling project. We had it disabled in Debug configuration but once it got (inadvertently) re-enabled I ran into many many IDE hangups while building the entire solution. And yeah, neither the build output nor the /log switch helped at all. – David Peters Jun 06 '14 at 14:24
  • The link is now busted yet I'm still experiencing this issue in VS2017. Microsoft Connect has been retired. I don't know exactly what a modeling project is, but this build issue is happening for me in a relatively modest, single-project solution that only I have worked on. No clue what's wrong or how to fix this unfortunately. :\ – Chad Jan 25 '20 at 18:49
2

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.

PersyJack
  • 1,736
  • 1
  • 21
  • 32
2

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.

K0D4
  • 2,373
  • 1
  • 27
  • 26
1

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.

David Cholt
  • 721
  • 4
  • 7
1

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!)

Robert Cody
  • 179
  • 2
  • 10
  • 1
    You don't actually need to comment. Just upvote that particular answer, since it's TL;DR same as what you said. And you have enough rep to upvote. – David Makogon Aug 03 '17 at 19:49
1

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

  • 4
    Note: it will delete any user data, including settings and extensions. – user31389 Feb 13 '19 at 16:32
  • 2
    It did not entirely wipe out my settings, (I still have my custom syntax coloring and keyboard shortcuts,) but it did reset the window layout, the theme, and all my extensions are gone. And it did not fix the issue. – Mike Nakis May 21 '19 at 14:05
1

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.

Kamarey
  • 10,832
  • 7
  • 57
  • 70
1

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.

The Sharp Ninja
  • 1,041
  • 9
  • 18
0

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.

komodosp
  • 3,316
  • 2
  • 30
  • 59
0

For me, killing the VS process from Task Manager and then Running VS as Administrator fixed the stuck build issue.

Hope it helps others.