.netvisual-studiorazorvisual-studio-2022roslyn

How to continue views compilation after first error in Visual Studio


I'm working on a .net project with lots of razor views (.cshtml), and after upgrading a dependency i will need to fix lots of errors.

Is there a way to prevent the compiler to not stop at the first error and instead make it so it compiles every view in the project, listing all the existing errors like it does in Jet Brains Rider?

Currently using Visual Studio 2022.


Solution

  • Even when you can get a compile & link tool such as Visual Studio to carry on despite errors you run the risk of cascade errors that make it problematic to locate the actual source of the error due to the sheer volume of problem reports.

    If you are looking for something to go through your code looking for potential problems and to list them all out for you then you will probably be better off running a linter. The trick of course is to find a linter that supports razor views (.cshtml) as well as your .net code.