09 July 2009

You can create new project templates in VS with your own predefined settings

When I create a new class library or another project type, there are a couple of properties I want to modify right away. This task can be a bit tedious (note to self: DRY), but luckily Visual Studio has a nice feature that allows you to create your own templates. It’s very easy, just make your changes and then select Export template… from the File menu. Make sure Automatically import the template into Visual Studio is checked if you want to use the template right away. What this checkbox does is simply to copy the resulting template zip file to the Visual Studio <Version>\Templates\ProjectTemplates sub folder under your documents folder.

Your new template is now available together with the other out-of-the-box templates when you create a new project:
 image

For those who are interested, these are the class library properties I modify:

  • Application tab
    • If I don’t name the project with full namespace, I change these two properties
      • Assembly name prefix
      • Default namespace prefix
    • Assembly information…
      • Company
      • Copyright
  • Build tab
    • Treat Warning as errors = All
  • Signing
    • Sign the assembly
      I’m adding my own self generated strong name key file
  • Code Analysis
    • Enable Code Analysis on Build
    • For Visual Studio 2010: Rule Set = “Microsoft All Rules”
      I’m running all rules as default and suppress individual messages as needed, but I haven’t evaluated the other rule sets to see if one of those are more appropriate for my needs

I also make a couple of other change in addition to the strong name to satisfy the code analysis rules. The first is to add the CLSCompliant(true) attribute to the AssemblyInfo.cs file, and the second is to suppress code analysis warnings on my name because it thinks my name is misspelled in the namespace of the library.

And lastly, I always remove the Class1.cs file :)

1 comment:

  1. I didn't know that it's possible. It's great that you can actually create a new project template in Visual Studio with your own predefined settings.

    business consultant

    ReplyDelete