2019-11-04

[SOLVED] Visual Studio 2019 keeps rebuilding my ASP.NET Core project when I refresh my browser

A couple of weeks ago, I started noticing that Visual Studio would rebuild my code whenever I would force a refresh in my browser, even if I had just rebuilt the solution in Visual Studio before executing said refresh.  Sometimes, Visual Studio would rebuild more than once during this process, and eventually would end up with a "Cannot copy the **** files because it is being used by another process" (which I imagine was the dotnet process handling the request.

I assume the multiple builds were because I was reloading a page that also turned around and made AJAX calls back to the same site.

It got beyond super annoying, and I searched the internet and dug through settings and could not find a workaround, until today.

Under "Tools" | "Options" | "Projects and Solutions" | "ASP.NET Core" you will find an option under the "General" category called "Auto restart Kestrel server after build".  It was set to "True" in my case, and I set it to "False" and it stopped the constant rebuilding for me.

Visual Studio 2019
Tools | Options | Projects and Solutions | ASP.NET Core
Notice the description of that option states:
"Automatically build modified ASP.NET Core projects hosted in IIS Express when a browser request is received."

Unfortunately this was happening to me even after I explicitly did a full rebuild in Visual Studio, then switched to my browser to refresh the page.  So I have no idea why VS thought it was "modified" but it wasn't.  I don't have time to track down the cause of this right now, so I consider this really more of a workaround than a solution, but I hope it will help someone else avoid this madness.

I would also like to know when this option was introduced... has it been there this whole time and always defaulted to "True" and I just happened to not be bit by it until a couple of weeks ago?  Perhaps the detection mechanism for determining an ASP.NET Core project was "modified" has been broken in a recent Visual Studio release?  (I'm currently on 16.3.7, but it was happening to me on at 16.3.6 as well.)

I'd love to hear from you if you have encountered the same thing and found a better explanation and/or solution.

No comments: