4

This is something I should really know how to do but I've never figured it out

How can I force Visual Studio to fail a compile based on what would ultimately be compile/syntax errors in ascx/aspx pages?

For example I could put the following into an ASPX page and the site would compile just fine, but obviously fall over if I visited this page;

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <% if (true) { %>
    <% if (true) { %>
</asp:Content>
plenderj
  • 563
  • 4
  • 15

1 Answers1

7

Ah just found this in the "related" questions to the right; How can I compile Asp.Net Aspx Pages before loading them with a webserver?

which links to; http://mikehadlow.blogspot.ie/2008/05/compiling-aspx-templates-using.html

So I've added the following as a post-build event to my project;

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler -v / -p "$(SolutionDir)$(ProjectName)"

and it works like a treat!

Community
  • 1
  • 1
plenderj
  • 563
  • 4
  • 15
  • 1
    It works, but it adds a lot of time to the build if you have a large application. I only do this once in a while as a "reality check" or after a major refactoring operation. – camainc Jul 09 '19 at 21:19