Change Startup.cs and wwwroot folder name in ASP.NET Core

ASP.NET Core runs on conventions. It expects Startup.cs file for starting up the ASP.NET Core application and wwwroot folder for the application’s static contents. But what if you want to change the name of Startup.cs and wwwroot to your choice? Well, that can be done. In this short post, we will see how to change Startup.cs and wwwroot folder name in ASP.NET Core.

Change Startup.cs class name

You can easily change the startup class name. Open the Startup.cs file and change the startup class name from Startup to “MyAppStartup” (or anything of your choice). And also change the name of the constructor.

public class MyAppStartup
{
    public MyAppStartup(IHostingEnvironment env)
    {
       
    }
}

Now you need to tell ASP.NET Core about new Startup class name, otherwise application will not start. So open Program.cs file and change the UseStartup() call as follows:

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<MyAppStartup>()
        .Build();
    host.Run();
}

That’s it.

Change wwwroot folder name

Earlier, I posted how to rename the wwwroot folder via hosting.json file but that doesn’t seem to work now. To change the name, right on wwwroot folder and rename it to “AppWebRoot” (or anything of your choice).

Now, open Program.cs file and add highlighted line of code to Main().

public static void Main(string[] args)
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseWebRoot("AppWebRoot")
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<MyStartup>()
        .Build();

    host.Run();
}

That’s it.

Hope you liked it. Thank you for reading. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in the comments section.

One thought on “Change Startup.cs and wwwroot folder name in ASP.NET Core

Leave a Reply

Your email address will not be published. Required fields are marked *

1 × five =