2

Our application registers events OnInit. When developers create a new aspx file from the visual studio template, it has AutoEventWireup="true". This leads to event handlers being registered twice and run twice.

Is there an easy way to cause the compile, build or other post build step to fail when the directives are set "wrong".

I'm using Visual Studio 2010 and TeamCity. I'm open to running any technology as a postbuild step.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
  • 2
    If you want them to be false by defualt.. http://stackoverflow.com/questions/1405721/setting-autoeventwireup-false-by-default – Erix Oct 28 '11 at 17:30

2 Answers2

2

You could precompile your site. Precompiling involves compiling the aspx and ascx files aswell as the .cs. It will make your site faster and it ensures things hook up a bit better, the downside is you cant change the aspx or ascx after you have compiled them.

http://www.dotnetperls.com/precompiled

This SO page describes a couple of ways of doing it Compile Views in ASP.NET MVC

Community
  • 1
  • 1
JonAlb
  • 1,702
  • 10
  • 14
  • I already precompile. This isn't a question about speed or the well formedness of the markup. AutoEventWireup="true" is a valid directive, but one that even MS documentation says that people shouldn't use for reasons I cited. Precompiling would catch AutoEventWireup="catfish", which isn't a problem I have. – MatthewMartin Oct 28 '11 at 18:12
  • My applogies. How about a variation of this: Paul Stack created a Html Validator for TeamCity, you could create a variation of this that does your own validation to ensure AutoEventWireUp is always False. http://paulstack.co.uk/blog/post/automated-w3c-validation-with-teamcity.aspx A second solution would be to change the default templates on the developers machines to ensure this isn't the default, centralizing the templates would allow you to agree on a best practice for your organisation. – JonAlb Oct 28 '11 at 18:27
1

You could try integrating StyleCop with TeamCity, and create a custom StyleCop rule that checks for this. Not sure how difficult it would be, but it's what comes to mind. See this question about using StyleCop with TeamCity.

Also, as suggested by Erix, update your templates to prevent this from being the default behavior.

Community
  • 1
  • 1
Jason
  • 86,222
  • 15
  • 131
  • 146