Search code examples
c#.net-corevisual-studio-2019visual-studio-templates

How To Modify Visual Studio's C# .Net Core Console App Project Template


As a student I find myself having to create tons of C# .Net Core Console Applications in Visual Studio. The thing is I also find myself having to use the System.Collections.Generic and System.Linq namespaces in virtually all my projects. But the only namespace that is included in Visual Studio's default C# .Net Core Console App template is System, so it is just annoying have to add those two namespaces every time I create a new project. So can I edit that template to include the two namespaces, and if so how? Also if I can I would also like to remove the project's namespace that is generated since all the projects are just a single file and I really don't think that that namespace is needed, it just clutters the file a little bit. And maybe also remove the Console.WriteLine("Hello world!") that is generated.

Ideally I would like the Program.cs file that is created when I use the template to look something like this:

using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args) {

    }
}

Instead of this:

using System;

namespace PROJECT_NAME
{
    class Program
    {
        static void Main(string[] args) {
            Console.WriteLine("Hello World!");
        }
    }
}

Solution

  • You can create a template in Visual Studio.

    • Open New Console App Project
    • Add your changes
    • Project -> Export As Template -> Project Template (Add Template Name, Icon and preview Image)

    More info How to: Create project templates