如何返回所有 aspnet_compiler 错误(不仅仅是第一个目录中的错误)

发布于 2024-09-03 05:43:40 字数 685 浏览 6 评论 0原文

有没有办法让 aspnet_compiler 遍历所有视图并返回所有错误,而不仅仅是当前视图目录中的错误?

例如,假设我有一个包含一堆文件夹的项目...

  • Views
    • 文件夹1
    • 文件夹2
    • 文件夹3
    • 文件夹4

其中两个(Folder2 和 < code>Folder3) 有错误。 aspnet_compiler 将运行,并且仅返回它在 Folder2 中遇到的错误。它不会同时返回 Folder3 中的内容。一旦我修复了 Folder2 中的错误并再次运行它,它就会拾取 Folder3 中的错误。我修复这些。然后必须再次运行该工具,直到全部修复为止。

这越来越烦人了!!

作为参考,这是我使用的命令:

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

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

趁微风不噪 2024-09-10 05:43:40

11 年后,我厌倦了自己重新运行 aspnet_compiler,并想出了一个奇怪的技巧...

  • 编写一个简单的 .exe (或 Linqpad 项目)将 aspnet_compiler.exe 加载到您的进程中。
  • AppDomain.FirstChanceException 设置一个事件处理程序,以接收所有 HttpCompileException 实例的通知。
    • 这些由 aspnet_compilerMain() 方法捕获,该方法在第一次尝试时失败。
    • 将导致 HttpCompileException 的文件名保存在 HashSet 中。
  • 然后运行 ​​aspnet_compilerMain 方法。
  • 如果抛出 HttpCompileException ,则您的程序具有失败的文件的名称,因此将该文件添加到 -x 编译器排除列表中并重新运行<再次使用 code>aspnet_compiler 的 Main 方法。
  • 并循环直到它完成并且没有错误 - 并且您将获得包含阻塞错误的所有文件的列表。

(我仍在整理执行此操作的 Linqpad 程序,我很快会将其发布到此答案)。我想知道@DanAtkinson 是否还能使用它......

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...

世态炎凉 2024-09-10 05:43:40

嗯...您可以让项目构建设置自动为您执行此操作,而不是通过命令提示符执行此操作。在文本编辑器中编辑您的项目文件,并在其中添加此设置(如果尚未添加)...

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

这应该编译您的所有视图并返回任何编译时错误(如果有)。此外,对于 ASP.NET MVC 项目,您可能需要通过将 MvcBuildViews 属性设置为 true 来启用它,因为默认情况下该属性处于禁用状态。

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

希望这有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文