How to return all aspnet_compiler errors (not just those in first directory)
Asked Answered
G

2

9

Is there a way to get the aspnet_compiler to go through all views and return all errors, rather than just the errors in the current view directory?

For example, lets say I have a project that has a bunch of folders...

  • Views
    • Folder1
    • Folder2
    • Folder3
    • Folder4

Two of them (Folder2 and Folder3) have errors. aspnet_compiler will run, and only return the errors it comes across in Folder2. It won't return those in Folder3 at the same time. Once I fix the errors in Folder2 and run it again, it'll then pick up the ones in the Folder3. I fix those. And then have to run the tool again, and again until it's all fixed.

This is getting annoying!!

For reference, here's the command I use:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler -v / -p "C:\path\to\project"

Thanks in advance!

Goeselt answered 26/5, 2010 at 15:42 Comment(0)
S
1

11 years later, I grew tired of re-running aspnet_compiler myself and came up with one weird trick...

  • Write a simple .exe (or Linqpad project) that loads aspnet_compiler.exe into your process.
  • Set-up an event-handler to AppDomain.FirstChanceException to be notified of all HttpCompileException instances.
    • These are caught by aspnet_compiler's Main() method, which fails at the first try.
    • Save the filename that caused the HttpCompileException in a HashSet.
  • Then run aspnet_compiler's Main method.
  • If an HttpCompileException is thrown, then your program has the name of the file that failed, so then add that file to the -x compiler exclusion-list and re-run aspnet_compiler's Main method again.
  • And loop until it completes with no errors - and you'll have a list of all files with blocking errors.

(I'm still tidying-up my Linqpad program that does this, I'll post it to this answer shortly). I wonder if @DanAtkinson can still use it...

Spilt answered 4/7, 2021 at 5:2 Comment(1)
Thank you. I'm no longer using anything that required compiled views in this way so the question is no longer relevant to me. If you update your answer with the Linqpad code you mentioned - and mention me in a comment - then I'll take a look and mark it as the accepted answer.Goeselt
V
-1

Hmmm ... rather than doing this via command prompt you can have your project build settings to do this for you automatically. Edit your project file in a text editor and add this settings in there if not already ...

<Target Name="AfterBuild" Condition="'$(MvcBuildViews)'=='true'"> 
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)..\$(ProjectName)" />
</Target>

This should compile all your views and return any compile time errors if any. Additionally for ASP.NET MVC projects, you might want to enable the MvcBuildViews property by setting it to true as it is disabled by default.

...
<MvcBuildViews>true</MvcBuildViews>
...

Hope this helps.

Viscous answered 28/5, 2010 at 16:54 Comment(2)
Yes, I already do this, but because it blocks the UI, I tend to run it every now and again in the command window.Goeselt
This answer doesn't address the problem of viewing all errors at once (or did I miss something?). Useful answer, but not for getting all errors...Reinold

© 2022 - 2024 — McMap. All rights reserved.