Automatically add .NET namespaces

I need to add this namespace to a C # file:

using System.Data;

Is there a way to automatically add this to newly created pages in C # .net?

I do not want to add this namespace to new pages.

+6
source share
6 answers

Open% Program Files% \ Microsoft Visual Studio 8 \ Common7 \ IDE \ ItemTemplates \ CSharp \ 1033 \ Class.zip, Or:% Program Files% \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ ItemTemplates \ CSharp \ Code \ 1033

You can modify the class.cs file in what is used to generate all the new C # source files - it looks like this:

using System; using System.Collections.Generic; using System.Text; namespace $rootnamespace$ { class $safeitemrootname$ { } } 

In addition, there is a Class.vstemplate file. Open this and you can edit the following:

 <Reference> <Assembly>System</Assembly> </Reference> <Reference> <Assembly>System.Data</Assembly> </Reference> <Reference> <Assembly>System.Xml</Assembly> </Reference> </References> 
+8
source share

You can create your own template ( see here ) that contains the separation of the namespace, or you can edit the existing template if you need it always and for each project.

+3
source share

I think you're out of luck, you have to add it to every page you create, since every page you create is a class.

0
source share

You must place it on all pages.

0
source share

You can edit the default element templates to add whatever you want or make your own. The default templates are here (or you get the essence of their location from my machine): C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ ItemTemplates

Understand that (at least in previous versions of VS) there was a template cache, so you will need to edit the encrypted template. Look for the directory with the same name as the zip file, and edit the templates in there / delete the directory.

Here's a nice blog post about this.

0
source share

You can put it in the web.config file.

  <pages> <namespaces> <add namespace="System" /> <add namespace="System.Collections" /> <add namespace="System.Collections.Specialized" /> <add namespace="System.Configuration" /> <add namespace="System.Text" /> <add namespace="System.Text.RegularExpressions" /> <add namespace="System.Web" /> <add namespace="System.Web.Caching" /> <add namespace="System.Web.SessionState" /> <add namespace="System.Web.Security" /> <add namespace="System.Web.Profile" /> <add namespace="System.Web.UI" /> <add namespace="System.Web.UI.WebControls" /> <add namespace="System.Web.UI.WebControls.WebParts" /> <add namespace="System.Web.UI.HtmlControls" /> </namespaces> <!-- Other elements --> </pages> 

This can be used to add a namespace on all pages.

0
source share

All Articles