views:

82

answers:

3

I've been manually adding the following line every time I create a new user control / web form in one of my ASP.NET web forms projects:

Option Strict On

I can't just set it in web.config because it's a legacy project that has user controls / web forms that would bomb out if we turned on option strict for the entire site, so the current solution is to apply it to all new user controls / web forms and slowly update the older pages. Is there some sort of Visual Studio setting / template I can change so that "Option Strict On" is applied automatically when Visual Studio creates the codebehind files?

A: 

modify your code templates for vs:

In the folder: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\Web\1033

Just open the zip file modify the contents and rezip.

Same works for other versions of visual studio as well.

Joshua Cauble
+1  A: 

Your templates are located in

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic

or

C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic

You can modify the name and other file information in your *.vstemplate but you're probably looking for the *.vb code and just placing the Option Strict On on top.

Yuriy Faktorovich
This worked for me with one addition: you need to refresh the ItemTemplatesCache after making the changes. You can do this by running "devenv /installvstemplates" after making changes to the templates.
Kevin Pang
+2  A: 
Russ Bradberry
Been so long since I did VB I forgot about that option, much easier than doing it by hand.
Joshua Cauble
Just fyi: doesn't seem to be an option in Visual Web Developer Express.
egrunin
@egrunin I edited the post to add in the web.config change
Russ Bradberry
Will this apply to all files in my solution or only newly created files? I mentioned that I can't have this apply to all files since I have older files that need to be left the way they are for the time being.
Kevin Pang
The first option should apply to the newly created files. The second will modify the compiler to compile the entire app in strict mode. I haven't used the first option in an ASP .NET app, so I'm not sure if it applies. If it doesn't work, then you will need to make a modification to the templates, as suggested by the other answers.
Russ Bradberry