3

How can I cause visual studio to automatically include a using statement like using System.Diagnostics, in every project?

I've been developing winforms applications and console applications and would like System.Diagnostics to be imported automatically with a using statement so I don't have to manually put the using statement in.

How can I do that?

barlop
  • 12,887
  • 8
  • 80
  • 109

3 Answers3

2

You need to edit this file:

(YourDriveNameHere):\Program Files (x86)\Microsoft Visual Studio 14.0\
                         Common7\IDE\ItemTemplates\CSharp\Code\1033\Class/Class.cs

To be like this:

using System;
using System.Collections.Generic;
using System.Diagnostics;
$if$ ($targetframeworkversion$ >= 3.5)using System.Linq;
$endif$using System.Text;
$if$ ($targetframeworkversion$ >= 4.5)using System.Threading.Tasks;
$endif$
namespace $rootnamespace$
{
    class $safeitemrootname$
    {
    }
}
Zein Makki
  • 29,485
  • 6
  • 52
  • 63
1

You can edit an appropriate class template for the Visual Studio so each new generated class will have using statements that you have put there.

For how to do this, check this question: How do I edit the Visual Studio templates for new C# class/interface?

Community
  • 1
  • 1
Ivan Yurchenko
  • 3,762
  • 1
  • 21
  • 35
0

Okay, you can do this the way @user3185569 told.

Also, there is a file named Class.vstemplate in that same directory. Open it and you can easily edit the following:

<TemplateContent>
        <References>
            <Reference>
                <Assembly>System</Assembly>
            </Reference>
            <Reference>
                <Assembly>System.Diagnostics</Assembly>
            </Reference>
            <Reference>
                <Assembly>System.Web</Assembly>
            </Reference>
            <Reference>
                <Assembly>System.Data</Assembly>
            </Reference>
        </References>

    <ProjectItem ReplaceParameters="true">Class.cs</ProjectItem>
</TemplateContent>
Community
  • 1
  • 1
Raktim Biswas
  • 4,011
  • 5
  • 27
  • 32