Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS 2010: Disable Fileheader for new class files

I recently noticed that Visual Studio 2010 (Professional) inserts a FileHeader automatically in new class files. I don't know when this started but some time ago this wasn't enabled. Also, since then the using directives are added after the namespace.

This is the way the file looks like after generation:

// -----------------------------------------------------------------------
// <copyright file="Class1.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace MyNamespace
{
   using System;
   using System.Collections.Generic;
   using System.Linq;
   using System.Text;

   /// <summary>
   /// TODO: Update summary.
   /// </summary>
   public class Class1
   {
   }
}

And thats the way it should look like (and how I want it):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyNamespace
{
   public class Class1
   {
   }
}

I disabled all extensions and all plugins, but the problem stays. Hopefully anyone here can tell my how to restore the previoous behaviour.

Thanks in advance

like image 966
Jan-Patrick Ahnen Avatar asked Jul 18 '11 14:07

Jan-Patrick Ahnen


2 Answers

Visual studio uses templates to generate new files. You can read about how to create your own templates here http://stevesmithblog.com/blog/how-to-fix-visual-studio-file-templates/. The default templates are commonly stored in C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates and it is these you'll want to edit if you want to globally replace the format.

like image 149
stimms Avatar answered Sep 23 '22 07:09

stimms


For me the file headers showed up after installing Resharper and Stylecop.

To get rid of them I disabled the header inclusions in Resharper (Code Cleanup section) and also made sure the file header rules are no longer enforced in StyleCop. Next I modified the file templates stimms mentioned earlier. And finally I had to run devenv.exe /installvstemplates from the command line for Visual Studio to register the changes.

like image 41
MoonStom Avatar answered Sep 22 '22 07:09

MoonStom