83

This applies to both 2008 and 2010 versions (and probably earlier ones too). Also to both C++ and C# projects.

An initial build (after reboot) runs at normal speed and with reasonably good CPU utilisation. After "some time" (ie using the computer for "stuff"), a subsequent build might run very, very slowly and with very low CPU utilisation. The only fix I have found seems to be a reboot, then the cycle starts all over again. This happens on both WPF and non-WPF projects, though it's 10 times worse with WPF.

This has happened to me on different machines, even working for different organisations, so I think it's a Visual Studio thing, not an environment thing. I've tried the usual (Google, turn off AV, Intellisense, Resharper etc, and currently looking forward to getting the SSD I have on order).

My current machine spec is 2.7gig quad core, 4GB RAM, XP (haven't got Win7 at work yet), 250Gb hdd etc

What is the the cause of the problem, and how can the problem be fixed?

starball
  • 20,030
  • 7
  • 43
  • 238
Maz
  • 831
  • 1
  • 7
  • 3
  • If I had to guess, I'd say that visual studio reserves itself a certain percentage of total available memory, which it uses for its cache. When there's less total memory available, theres less VS memory, and thus less caching. I don't know, though. – Phillip Schmidt Aug 23 '12 at 16:04
  • Running into the same problem with VS2010 and WPF -- I've got an SSD and it doesn't help any. – BrainSlugs83 Jun 30 '14 at 03:38
  • Hmm. I have had this for years on multiple machines with VS2008 and VS2010 with native c++ however it seems to have gone away as I do not recall seeing this recently. – drescherjm Aug 05 '14 at 13:32

24 Answers24

135

Try this as it worked for me:

Press Windows+R or open run from Start.

Now type %temp% and delete everything from there...

Now open Run again and type prefetch and delete everything from there also.

Now open VS and see the performance.

Ugnius Malūkas
  • 2,649
  • 7
  • 29
  • 42
Sam
  • 1,359
  • 1
  • 8
  • 2
  • 6
    Wow, the prefetch did the trick. I deleted all the %temp% files, and gained back about 3GB, but that didn't fix it. Removing the content from prefetch did it! – agarcian May 15 '15 at 19:32
  • Use `ccleaner` and include from options the folders `%temp%` and `prefetch`, the download link https://www.ccleaner.com/ccleaner/download/standard – Ashraf Sada Jun 07 '19 at 13:00
32

Try this:

Devenv.exe /resetsettings

jurget
  • 329
  • 3
  • 3
  • This flag fixed issues I was having with VS2010 hanging on startup. Will remember it for the future! – Henry Wilson Oct 07 '13 at 11:44
  • 4
    I have just had same issue in 2012/13. Go to Tools / Import Export Settings / reset. solved it. The problem was caused by a power outage while in hibernate and I guess the settings file got corrupted. – 27k1 Nov 14 '13 at 14:28
  • @jurget Thanks. This got me out of a jam where something between the the Azure SDK update and my other web related settings in Visual Studio caused any web related operations to execute incredibly slowly, even running the web site locally. Not sure if it matters, but I also executed that command while I was in an administrator level command prompt. – Robert Oschler Mar 31 '16 at 00:14
21

I had the same problem.

I had McAfee security center installed, by disabling the "Real time scan"

Building times did go from 40 seconds for a small project to 1 second.

18

Check your power saving settings in Windows. Set it to "High performance" (even on desktop). This helped for me.

Gijs Mater
  • 311
  • 2
  • 5
  • 1
    I am using VS2015 on Windows 10 and had the same issue. I cleared the %temp% and prefetch directories. Then i reset the devenv.exe setting but they didn't help. Then I changed the power saving settings from Balanced to High performance and it worked. CPU gets started utilizing 100%. It CPU usage was not increasing beyond 30% – irsis Aug 09 '16 at 11:06
  • 1
    After the sudden power lost in our campus, I got the VS 2015 build issue. It takes forever to build a solution. That is the method to make it works. That method seems so strange, but it really works. Thanks. – Boveyking Jun 02 '17 at 16:24
  • 1
    For curiosity, I changed back the power plan to balance and started to build the solution, it stuck again. Then changed back to high performance, it built. It seems that is only method for me to get VS working. I am so fortune to live in such a wonderful world and work in such a marvelous field. I witness miracle every day. – Boveyking Jun 02 '17 at 16:42
  • uowwwwwwwwwwwwwwwww... I was having slow build, and this worked for me... Also, I was facing a delay after stop debugging, that was solved by deleting all breakpoint (there was many deactivated breakpoints)... Now working got much better... thanks for this answer... I`m sure this change will give me other performance improvements.. – Fernando Meneses Gomes May 09 '18 at 13:20
  • Also check the fan setting if u have a laptop. If the fan isnt at 100%, the CPU can't be fully used, even if CPU usage is 100% – Markus Apr 30 '21 at 12:08
10

Try to use ProcessMonitor (http://technet.microsoft.com/en-us/sysinternals/bb896645) to find what the Visual Studio doing during build process. Add the Filter "ProcessName is devenv.exe then Include" and make some research. It was useful for me.

I have a similar problem - very slow build and debug process - and I can solve it with Process Monitor. I run Process Monitor and saw that Visual Studio process read and write some HTL files many times. It was the Assembly Binding Log (http://msdn.microsoft.com/en-us/library/vstudio/e74a18c4(v=vs.100).aspx) - the utility that store information about libraries binding. Once I enabled this log, and this utility create about 8 Gb HTM logs on my hard drive ) It was very slow. Then i disable logging, the building time of my project decreases from 10 minutes to 10 seconds!

Kosix
  • 111
  • 1
  • 3
5

am using VS2015 on Windows 10 and had the same issue. I cleared the %temp% and prefetch directories that didn't work.Then I changed the power saving settings from Balanced to High performance and it worked.

dhina s
  • 51
  • 1
  • 2
3

I did not see this type of answer, so I am thinking that mine, might be helpful to someone. My issue with VS build time was a dumb one: I had the source code on another computer. Each time I tried to build it, a connection has to be made to that computer, which results in VS freeze time for a long time. I discovered this issue, after trying most of the solutions here and elsewhere. (emoticon with banging my head against the desk)

Gabriel Marius Popescu
  • 2,016
  • 2
  • 20
  • 22
2

I had the same issue. Deleting the hidden .vs folder in the solution directory solved the problem.

György Kőszeg
  • 17,093
  • 6
  • 37
  • 65
2

One of the reasons, is Visual Studio keeps rebuilding the same dependent project(s) over and over although nothing has changed. Imagine a Solution having tons of Projects that keep being built for no apparent reason. This wastes HUGE time...

The main solution to this is to revise each "Copy to Output Directory" where it's set to "Always". Change that to "Copy if newer".

It might help to see detailed build log. Open Tools > Options > "Projects and Solutions" > "Build and Run". Now set "MSBuild project build output verbosity" to "Diagnostic"

For more info, this thread discusses this specific point

Korayem
  • 12,108
  • 5
  • 69
  • 56
2

Go to Tools > Options > "Projects and Solutions" > "Build and Run". Now set "MSBuild project build output verbosity" to "Normal" or "Minimal" and same for the other setting "MSBuild project build log file verbosity".

I earlier set it to "Diagnostics" which resulted in long build time duration.

Vikram
  • 1,617
  • 5
  • 17
  • 37
1

My fix for very sluggish Visual Studio (building anything took about 1.5-2 min) was to turn off the wireless network.

I had enabled the Wireless Network in addition to the wired one. It seems like my computer tried to use the wireless connection to connect to our local server that is not available to wireless network and that caused the long delay.

Antti
  • 101
  • 1
  • 7
  • Can you shed some more light on this? -- How exactly does the network speed influence Visual Studio's build time? -- At any rate, I have the above described issue on a desktop (with no Wireless network card). – BrainSlugs83 Jun 30 '14 at 03:44
  • 1
    This happened so long time ago that I don't remember the exact details, but it was approximately so that when I had the wireless network connected, for some reason the build process tried to connect to a network drive and waited for the windows's default network location timeout before it continued the build. When I closed the wireless network (that didn't allow access to our network drive) and used only the wired network (that provided access to the network drive) the build process got very much faster. – Antti Jul 01 '14 at 09:27
  • visual studio try to connect to MS server and download some information. if your internet connection is OFF build run normally. – Ali Amanzadegan May 10 '19 at 10:22
1

Take a Backup of Files and Delete everything in the folder in this folder.

C:\Users\{username}\AppData\Local\Microsoft\WebsiteCache

Restart Visual Studio and Check the performance.

Hope this helps! Thanks

cpoDesign
  • 8,953
  • 13
  • 62
  • 106
Mohamed Alikhan
  • 1,315
  • 11
  • 14
1

If there are many project in a single solution, try building the changed one only rather than building the whole solution. Namely, Alt+B+U rather than Alt+B+B.

cheny
  • 2,545
  • 1
  • 24
  • 30
1

If it's an ASP.NET MVC project, check the .csproj to see if <MvcBuildViews>true</MvcBuildViews> is set. This can cause slow builds.

bkaid
  • 51,465
  • 22
  • 112
  • 128
0

About how long is "Some time"? (eg, Hours? Days?)

It could be as simple as you've run out of RAM.. Ctrl-Shift-Esc will load the Process Monitor where you can see your memory utilization, and kill hogs. Once it's run low, your linkers will slow down trying to swap memory to disk (and Windows doesn't typically report swap overhead unless you turn on System utilization). Depending on the size of your project, Linking can use HUGE amounts of memory making tables.

Yeraze
  • 3,269
  • 4
  • 28
  • 42
  • 1
    Nope, plenty of RAM (eg 1.5Gb used of 4Gb), so pretty sure it's not thrashing the disk. "Some time" is often the 2nd or 3rd build after a reboot, maybe with a bit of debugging prior to that. Haven't been able to find anything useful out in Proc Explorer. The only "clue" is that after a reboot, it works fine for a while. Question is, what gets round to clogging up the machine after a couple of build/debug sessions? Thanks – Maz Aug 24 '12 at 08:42
  • 1
    I run into the issue (with WPF projects on VS 2010) on both my 8 GB and 16 GB machines (with more than 50% available in both cases, 16 GB is a 2.2 GHz quad-core with HT, 8 GB is a 3.2 GHz AMD hexa-core). – BrainSlugs83 Jun 30 '14 at 03:39
  • Sorry for the downvote, was accidental and can't reverse it. Can revert it if the answer is edited. – Krzysztof Bociurko Apr 05 '18 at 09:57
0

At some point I had a programme which took considerably more time to compile after a few weeks. Out of frustration I deleted the debug folder of the solution and projects. What visual studio did was first rebuild the entire solution (which does take some time) but after that, the building process had its old speed back. Not sure if it will work for you as well.

JMRC
  • 1,473
  • 1
  • 17
  • 36
0

check your Internet Properties option (connections) and make sure Automatically detect settings is checked.

ewwink
  • 18,382
  • 2
  • 44
  • 54
0

As a quick check, run a scan to make sure you don’t have anything currently infecting your system, and then go to Windows Defender Security Center-> Virus & threat Protection -> Disable Real-time protection:

real-time-protection

Rebuild your solution in Visual Studio, noting the total time it takes and observing in Task Manager to see if the Antimalware Service Executable appears to be consuming significant processor time. Assuming your build is faster and your CPU less busy, congratulations, you’ve identified one cause of your performance problems. The next step is to responsibly tell Windows Defender to leave Visual Studio alone without turning it off completely.

0

In my case, I used "wwwroot" directory inside the project directory to store couple GB of data. Moving the "wwwroot" outside the solution directory solved my build times. For my .NET Core web app, I edited launchSettings.json and added new environment variable ASPNETCORE_WEBROOT:

...
"profiles": {
    "Development": {
      "commandName": "Project",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_WEBROOT": "../../wwwroot"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },
...
xhafan
  • 2,140
  • 1
  • 26
  • 26
0

Since I came here via a Google search, I'll post what I found as the solution for my specific issue.

I had upgraded from .NET Core 1.1 to .NET Core 2.1. This caused the RazorGenerate and RazorTagHelper calls to take 20 seconds each. According to Daniel Crabtree, this was caused by a change in .NET Core 2.1 which enables pre-compiling of Razor views by default.

The fix is to add the following to your .csproj:

<PropertyGroup>
  <UseRazorBuildServer>false</UseRazorBuildServer>
</PropertyGroup>

Source: https://www.danielcrabtree.com/blog/444/speed-up-compilation-of-asp-net-core-2-1-projects

0

In YourProject.csproj, add the target tag in the last line of your project tag

<Project>
.
.
<Target Name="PlatformVerificationTask" Condition="'$(SkipPlatformVerification)' 
    != 'true'" />  
</Project>
Khant Htet Naing
  • 128
  • 1
  • 3
  • 11
0

I've updated all the NuGet packages and it worked!

Daniel Lobo
  • 2,144
  • 1
  • 13
  • 6
-1

Same issue with any command or function that I was running on VS. After antivirus REAL TIME PROTECTION disabling, the running time was reduced from 10 second to 0.5 or even less seconds. By the way, interesting thing was that antivirus's actions were slowing down the C# running time, but the C++ was totally fine.

  • While your experience may be true, OP stated they already turned off antivirus entirely and that it did not help. Additionally, they were also having issues with the C++ side. Glad you could find your solution, though. – Orion Jul 20 '19 at 18:05
  • Well, as I see from the comments, this issue has different solutions for different PCs (or the reason is also the concrete type of antivirus, because mine was "Avira Antivirus") – Bear Grylls Jul 21 '19 at 20:10
-3

Move Your Project from SATA to SSD. Install Visual studio in SSD

  • That makes a speed difference, but it is reliable. The question asks about Visual Studio getting into some rut where it is slow and has low resource utilization. As a result, some tasks which normally run instantly take minutes—even on the same computer without changing hardware—until Visual Studio randomly “decides” to be performant again. – binki Apr 14 '22 at 20:43