1

i have a Project, which is quiet big. I would like when adding a new class that this class would have automatically a header which could be designed like the one in this thread. Is there a possibility to set that in Visual Studio? The next thing is that there are a lot of classes which doesn't have a header. Is there a possibility to change this automatically? Are there already some solutions.

Many thanks in advance!

Community
  • 1
  • 1
a_hamm99
  • 171
  • 1
  • 12

1 Answers1

1

Create a custom item template:

Create a .cs file with the header the way you want it.

Go to File -> Eport Template

Choose Item Template

select the project that has your file

click Next

Select your file

Next

Select References

Next

Set name, description, images You can use any image but you may want to pick one out of the Visual Studio image gallery

Choose Automatically import template into visual studio

Next

Now when you right-click a project and select New Item your template will be in the list with all the other templates. You may need to search for it. You will also have a zip file that you can give to others for importing into their Visual Studio.

You can get more elaborate if you need to prompt a user for information but this requires a .vsix project.

As far as what to do about pre-existing classes - you will either have to open them all and paste the header in or write some code that goes through the folders of your solution, somehow identifies the .cs files you want (by namespace maybe?) and append the header. The .cs files are just text after all.

Crowcoder
  • 11,250
  • 3
  • 36
  • 45