How to define default code when creating a new C # class with Visual Studio 2010

Creating a new class in VS10 gives me

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Foo { class Bar { } } 

Is it possible to configure VS10 to get this instead?

 namespace Foo { public class Bar { } } 
+4
source share
2 answers

Yes, you can change it. See this article for a decent passage.

Here's a bounce from an article that explains where to find the template:

Step One - Find a Template

Visual studio 2010

64 bit:

C: \ Program Files (x86) \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ ItemTemplates \ CSharp \ Code \ 1033 \ Class.zip

32 bit: C: \ Program Files \ Microsoft Visual Studio 10.0 \ Common7 \ IDE \ ItemTemplates \ CSharp \ Code \ 1033 \ Class.zip

Step two - change the template

Extract the zip file.

Using a text editor, open the Class.cs file.

Save the file.

Restore the zip file with the new Class.cs. Be careful that the zip file is correct.

Copy the new zip file back and overwrite the existing one

Step Three - Update VS

Open a command prompt as an administrator.

Change to the appropriate directory and run the command:

devenv.exe / installvstemplates

+3
source

Yes, you can. This MSDN article http://msdn.microsoft.com/en-us/library/s365byhx.aspx has links to several approaches to achieve this.

I think that the easiest way is to create a file with the desired template, substitute parameters and export the template. In your example, create a new class with an existing template

  namespace Foo { public class Bar { } } 

Translate the variable parts of this. those. namespace name 'Foo' and class name 'Bar'

  namespace $rootnamespace$ { public class $safeitemrootname$ { } } 

Save changes

  • Now you can go to File → Export Template. Select an item template (click Next)
  • Select the file created for this example (click "Next")
  • Select any links to the objects that you want to add to the project. In that
    case no (click next)
  • Enter a name for the template (i.e. PublicClass). This is what the file will be called in the dialog box of the new file. Also, the default file will be called upon creation

This will create a zip file in {userpath} / My Documents / Visual Studio 2010 / My Exported Templates. You do not need to run an administrator or run any other tools. VS will automatically get it out of this way.

I understand that this does not replace the existing option. If you want to do this, I would use the same process using the same element name as the default element name. In this case, the class. I would use the registration path and process defined by @James Hill

+1
source

Source: https://habr.com/ru/post/1398293/


All Articles