Optimizing C# Refactoring Performance with Web Projects in VS 2005
One complaint I've heard a lot is the performance of the new C# refactoring feature with web pages in VS 2005. VS 2005 added support for enabling refactoring everywhere (for example: even within <% %> blocks defined inline with a .aspx page), which is nice from a feature-completeness perspective. The problem, though, is that by checking every file and possible context, it can end up slowing down performance considerably. The more pages you have in a project, the slower and slower refactoring gets (to the point of being unusable).
Unfortunately, with the current UI there is no way to tell the refactoring engine to "include/exclude" pages or individual projects when you do a refactoring change (ideally there would be a checkbox for indicating whether you wanted <% %> blocks, <script runat="server"> events, etc. checked or not so that you could configure this and turn off the overhead if you don't need it -- which for a lot of people is most/all of the time). The C# team is investigating ways to enable these scenarios, as well as increase refactoring performance for the first SP.
One optimization trick that you can make before that, though, is to set a registry entry that will exclude ASP.NET pages and inline .asmx and .asax code from being included as part of a C# refactoring operation. C# class files defined under the \app_code directory in web site projects will be included as part of the refactoring operation when this registry entry is set, as well as all ASP.NET code-behind pages that are open in VS at the time that you apply the refactoring (note: the C# parser already has these files open so refactoring is very fast). The re-factoring will also continue to work across all other class libraries and projects in the solution.
To apply this registry setting:
- Close all running instances of VS 2005
- Click Start->Run in Windows and run "regedit"
- Navigate to this registry location: HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\8.0\CSharp\Options\Editor
- Right-click on the Editor node and choose "New DWORD value"
- Name the value "OpenAllVenusFilesOnRefactor" and leave the value as 0
Then, when you restart VS 2005 and perform a re-factoring - you should find performance very fast. It isn't as complete a check as before, but for many cases it might end up being much more useful than before.
Hope this helps,
Scott
P.S. VS 2005 Web Application Projects don't compile the .aspx portion of files, and don't support refactoring code within them, so they also don't have an issue with refactoring performance.
Update: Raj implemented the trick above and apparently saw his refactoring perf go from 1 minute 10 seconds to less than a second. Cool! :-)