Automatically add namespace when adding new item

前端 未结 4 402
暖寄归人
暖寄归人 2020-12-08 23:55

When adding a new item (class, control, etc) in C# it will automatically add a namespace to the file depending on the location in the project.

Is this also available

4条回答
  •  有刺的猬
    2020-12-09 00:36

    You dont say what version of visual studio you are using, but it is doable by default with VS2008.

    Goto : C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\Code\1033\Class.zip (if this doesnt exist i will post you the contents of mine).

    Inside you will find two files: Class.vb and Class.vstemplate

    Open Class.vb (i extracted it and edited in notepad++ but anything will do). Change it to read:

    Namespace $itemfolder$
    
        Public Class $safeitemname$
    
        End Class
    
    End Namespace
    

    Shut Visual stuid (all instances)

    Save and replace the one inside the zip.

    Openup a command prompt (easiest is to use the visual studio command prompt), and run the following:

    devenv.exe /InstallVSTemplates
    

    Open Visual Studio again, create a blank project and add a folder to the project, and add a class inside the folder and you will have your namespace automagically added to your class file.

    Edit

    Class.vb:

    Namespace $itemfolder$
    
        ''' 
        ''' 
        ''' 
        ''' Class Created by $username$ on $date$
        Public Class $safeitemname$
    
        End Class
    
    End Namespace
    

    Class.vstemplate:

    
      
        
        
        
        VisualBasic
        100
        Class.vb
        1
        Microsoft.VisualBasic.Code.Class
        2.0
      
      
        Class.vb
      
      
        VBClassTemplateWizard, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=f12a64f29cf5aee5
        VBClassTemplates.VBClassReplacements
      
    
    
    

提交回复
热议问题