This problem has got to annoy at least someone as much as it annoys me:

  1. You close a Web project and open another than has a similar folder structure
  2. You attempt to create a folder that existed in the previous web project but not in the new one.
  3. Visual Studio tells you that the folder already exists
  4. You swear and delete everything in c:\Documents and Settings\[Username]\VSWebCache\[ComputerName]
  5. You close and open the project
  6. You create the folder

To solve this annoying problem, I came up with an EnvironmentEvents macro a while back that cleans up the VSWebCache folder when you close a solution that contains a web project. To implement, paste the code below into a EnvironmentEvents macro module.

    Private PerformCleanup As Boolean

    Private Sub SolutionEvents_AfterClosing() Handles SolutionEvents.AfterClosing

        If (PerformCleanup) Then
            Dim psi As New ProcessStartInfo("cmd", "/C rmdir /Q /S ""%homedrive%%homepath%\VSWebCache\%computername%""")
            psi.CreateNoWindow = True

            psi = New ProcessStartInfo("cmd", "/C mkdir ""%homedrive%%homepath%\VSWebCache\%computername%""")
            psi.CreateNoWindow = True
        End If
    End Sub

    Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing
        Dim isWebProject As Boolean = False

        Dim prj As Project
        For Each prj In DTE.Solution.Projects
            If (prj.Properties.Item("ProjectType").Value = 1) Then
                isWebProject = True
                Exit For
            End If

        PerformCleanup = isWebProject
    End Sub