4

We have an ASP.NET website which uses .NET framework 4.6, and we use rider and visual studio to work on it.

Every once in a while, I have found people getting old razor files that still try to look for functions/references which no longer exist. I understand that those razor files are cached, and we need to clear the cache.

So, we usually go to these steps

  1. Clean %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\\ComponentModelCache
  2. Clean C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root
  3. Clean the \obj and \bin from the project folder structure, wherever applicable.

Some combination of these steps usually work for most people but when it doesnt work, we have to manually go to each razor file (which is complaining with error) and add a space and save it to force clear the cache. Sometimes it a single file or 2 files, but sometimes there are 10 files.

So, would like to know what's the right/recommended way to clear the razor file cache whenever we find this problem again.

Mike Brind
  • 28,238
  • 6
  • 56
  • 88
Yasser Shaikh
  • 46,934
  • 46
  • 204
  • 281

1 Answers1

0
  1. If you need to clear out the compiled razor files, then "Temporary ASP.NET Files" is the best location, as per this answer.

  2. You could also try to force compilation by adding MvcBuildViews to your build configuration:

    <PropertyGroup>
      <MvcBuildViews>true</MvcBuildViews>
    </PropertyGroup>
    

    See this answer for more information.

  3. If none of the above works, a slightly better workaround than opening all the files and adding a space is to update the file modification time of all your views:

    Get-ChildItem .\Views\ -Recurse | % { $_.LastWriteTime = Get-Date }
    
Will
  • 2,086
  • 23
  • 30