1

I am trying to make custom template project in Visual Studio 2019. In my template Project directives should be inside the namespace. while coding I am keeping them inside. But when project generated I see them outside(my code is overwritten).

How can I make Visual Studio to place using statements in the namespace for every new project created using custom project template?

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27
  • 2
    Why not stick to the pattern that most people use (i.e. using outside of namespace)? – Ackdari Mar 05 '21 at 08:28
  • 1
    This one should help you : https://stackoverflow.com/questions/125319/should-using-directives-be-inside-or-outside-the-namespace – Arcord Mar 05 '21 at 08:31
  • 1
    You can edit the template file used to create new class files: https://stackoverflow.com/questions/2072687/how-do-i-edit-the-visual-studio-templates-for-new-c-sharp-class-interface – Matthew Watson Mar 05 '21 at 08:51
  • I read it already @arcord. The dicussion went in other direction. wheather to keep it inside or outside the namespace. I could not get what I need from that post. In my case, my custom project template should write directives inside the namespace.which is not happening. Some how I should forced VS to do that. I doono how to do that. Thank you – manikanth reddy Mar 05 '21 at 09:15
  • Thank you @MatthewWatson. This is also not working in my case. This is working when I try to create a class manually. In my case, class in project template is overwritten while creating a new project – manikanth reddy Mar 05 '21 at 09:41

1 Answers1

5

Have you tried You need to setup your preferred placement. You can find this option in the following path:

  • Options
  • Texteditor
  • C#
  • Code Style
  • change Preferred 'using' directive placement to Inside namespace

Preferences

Christian Gollhardt
  • 16,510
  • 17
  • 74
  • 111